Jump to content

single quotes


etsted

Recommended Posts

$previous = '';

$paginationCtrls .= '<a href=" ' . $_SERVER['PHP_SELF']. '?pn=$previous">Previous</a>';

$paginationCtrls .= '<a href="$_SERVER['PHP_SELF']?pn=$previous">Previous</a>';

 

only the second code Works, becuase i have used single quote concatination, why doesnt the third line work?

Link to comment
Share on other sites

not in the third example, because you have single quote, double quote, then single quote. It considers the second single quote the end of the first one.

Link to comment
Share on other sites

Not necessarily, but you need to read the code from left to right. When a quotation mark appears, the string is open, when the same type of quotation mark appears again the string is closed. Syntax highlighters do this for you. You should be able to see clearly here:

$paginationCtrls .= '<a href=" ' . $_SERVER['PHP_SELF']. '?pn=$previous">Previous</a>';$paginationCtrls .= '<a href="$_SERVER['PHP_SELF']?pn=$previous">Previous</a>';

You can use double-quotes and complex string syntax. That requires escaping any double-quotes that are in the string with

<?php$paginationCtrls .= "<a href="{$_SERVER['PHP_SELF']}?pn=$previous">Previous</a>";?>
Link to comment
Share on other sites

but u are supposed to use them With links

PHP doesn't care what is in the string. It doesn't matter to PHP if you have a string of HTML code or whatever else. PHP has no knowledge about what you are outputting, it will not validate HTML code for you for example. As far as PHP knows, you start a string with a single quote, the next single quote ends the string, and then it sees a bunch of stuff it doesn't understand. It doesn't matter if it is HTML or a link or anything else.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...