n"; I remembered that the end mark allowed by the PHP interpreter can also be commented with a single line, that is, //$str .= "?>n"; before it is interpreted as an end mark. Annotated, annotated content"/> n"; I remembered that the end mark allowed by the PHP interpreter can also be commented with a single line, that is, //$str .= "?>n"; before it is interpreted as an end mark. Annotated, annotated content">
Home > Article > Backend Development > syntax error PHP syntax error, unexpected $end One cause and solution of the error
Parse error: syntax error, unexpected $end in script.php on line xx
After debugging for a while, I found that the line that caused the error was a line in the middle of the file
//$str .= "?>n";
I remembered it The line with the end mark allowed by the PHP interpreter can also be commented with a single line, that is, //$str .= "?>n"; is interpreted as a comment before the end mark, and the content of the comment is //$str .= ", And the n"; after ?> will be interpreted as the content outside the PHP block and output as HTML! The result is that after adding // to the $str .= "?>n"; line as a comment, there is an additional end tag of ?>, causing the original real end tag to become unexpected. .
The solution is to simply delete this line.
PHP It is a good habit not to write anything else on the line where the opening and closing tags are.
The above introduces a cause and solution of syntax error PHP syntax error, unexpected $end error, including the content of syntax error. I hope it will be helpful to friends who are interested in PHP tutorials.