etsted Posted April 3, 2014 Share Posted April 3, 2014 $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 More sharing options...
justsomeguy Posted April 3, 2014 Share Posted April 3, 2014 Because the quotes around PHP_SELF are breaking the rest of the string. Link to comment Share on other sites More sharing options...
etsted Posted April 4, 2014 Author Share Posted April 4, 2014 But wont the double quotes keep it all together? Link to comment Share on other sites More sharing options...
thescientist Posted April 4, 2014 Share Posted April 4, 2014 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 More sharing options...
justsomeguy Posted April 4, 2014 Share Posted April 4, 2014 The double quote is part of the data inside the string. It has no special meaning, it's just a character like any other character inside the string. Link to comment Share on other sites More sharing options...
etsted Posted April 5, 2014 Author Share Posted April 5, 2014 but u are supposed to use them With links Link to comment Share on other sites More sharing options...
Ingolme Posted April 6, 2014 Share Posted April 6, 2014 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 More sharing options...
justsomeguy Posted April 7, 2014 Share Posted April 7, 2014 but u are supposed to use them With linksPHP 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now