Jump to content

Where Is The Error?


yangkai9999

Recommended Posts

hello,I got error message, say "Parse error: syntax error, unexpected '"' in C:\wamp\www\MyTest2\p1_browse v2.php on line 30"the code is:29. if($pg > 1){ $prev = ($pg - 1); // Previous Link 30. $paginator ="<a href="".$_SERVER["PHP_SELF"]."?pg=$prev">"Previous page</a>""; } Anyone can tell me where is the problem for the part of PHP code?Thank you,

Link to comment
Share on other sites

"<a href="".$_SERVER["PHP_SELF"]."?pg=$prev">"Previous page</a>""We see this kind of error often when developers are echoing a combination of HTML attributes and PHP values. What you consider "internal quotes" are not considered that way by the interpreter. You see this: "<a href="" as an opening quotation mark inside two external quotation marks. But the interpreter sees the one I marked in red as a closing mark for the first mark. So it has no way of understanding the next quotation mark at all. So that is the unexpected '"'. We can improve all this with some interpolation, single quotes, and escaped quotes, like this:"<a href=\"{$_SERVER['PHP_SELF']}?pg=$prev\">Previous page</a>"There are other ways to do it, but I personally find this the most readable. Note that $prev will be interpolated inside the outer double quotes just as it is. Array values need to be surrounded by braces.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...