T_STRING is a bit of a misnomer. It does not refer to a quoted "string". It means a raw identifier was encountered. This can range from bare words to leftover CONSTANT or function names, forgotten unquoted strings, or any plain text.
This syntax error is most common for misquoted string values however. Any unescaped and stray " or ' quote will form an invalid expression:
Syntax highlighting will make such mistakes super obvious. It's important to remember to use backslashes for escaping \" double quotes, or \' single quotes - depending on which was used as string enclosure.
For convenience you should prefer outer single quotes when outputting plain HTML with double quotes within.
Use double quoted strings if you want to interpolate variables, but then watch out for escaping literal " double quotes.
For lengthier output, prefer multiple echo/print lines instead of escaping in and out. Better yet consider a HEREDOC section.
If you miss a closing " then a syntax error typically materializes later. An unterminated string will often consume a bit of code until the next intended string value:
echo "Some text", $a_variable, "and some runaway string ;
It's not just literal T_STRINGs which the parser may protest then. Another frequent variation is an Unexpected '>' for unquoted literal HTML.
If you copy and paste code from a blog or website, you sometimes end up with invalid code. Typographic quotes aren't what PHP expects:
$text = Something something.. + these ain't quotes;
Typographic/smart quotes are Unicode symbols. PHP treats them as part of adjoining alphanumeric text. For example these is interpreted as constant identifier. But any following text literal is then seen as bareword/T_STRING by the parser.
If you have an unterminated expression in previous lines, then any following statement or language construct gets seen as raw identifier:
PHP just can't know if you meant to run two functions after another, or if you meant to multiply their results, add them, compare them, or only run one || or the other.
This is rather uncommon. But if short_open_tags are enabled, then you can't begin your PHP scripts with an XML declaration:
PHP will see the <? and reclaim it for itself. It won't understand what the stray xml was meant for. It'll get interpreted as constant. But the version will be seen as another literal/constant. And since the parser can't make sense of two subsequent literals/values without an expression operator in between, that'll be a parser failure.
A most hideous cause for syntax errors are Unicode symbols, such as the non-breaking space. PHP allows Unicode characters as identifier names. If you get a T_STRING parser complaint for wholly unsuspicious code like:
You need to break out another text editor. Or an hexeditor even. What looks like plain spaces and newlines here, may contain invisible constants. Java-based IDEs are sometimes oblivious to an UTF-8 BOM mangled within, zero-width spaces, paragraph separators, etc. Try to reedit everything, remove whitespace and add normal spaces back in.
The extra ; semicolon here will convert the preceding invisible character into an undefined constant reference (expression as statement). Which in return makes PHP produce a helpful notice.