help understanding this line of code...

Problems with the Windows version of XAMPP, questions, comments, and anything related.

help understanding this line of code...

Postby hem » 08. July 2009 05:17

echo '<p><a href=" ' . $_SERVER['PHP_SELF'] . ' ?addjoke=1">add a joke!</a></p>';

This line of code is from Build your own database driven book. In the above mentioned code i am not able to understand the use of both single and double quotes. i mean which quote escapes which one? :idea:
Posts: 7
Joined: 18. June 2009 13:08

Re: help understanding this line of code...

Postby aldo » 08. July 2009 07:38

None of those escape one another. It is just usually with HTML you use double quotes... To avoid having to escape the double quotes with a backslash, single quotes are used to tell the PHP Parser where the PHP code begins and ends...
Posts: 13
Joined: 17. July 2008 08:10

Re: help understanding this line of code...

Postby glitzi85 » 09. July 2009 13:08

In PHP you can use both, single and double quotes. Small example:

Code: Select all
$test = 'hem';
echo "Hello $test";
echo 'Hello $test';

Output would be:
Code: Select all
Hello hem
Hello $test

Text inside double quotes will be parsed by PHP, in single quotes not. That means, that single quotes are faster, but double quotes may not blow up your code.

When using HTML inside PHP i prefer single quotes, otherwise you need to escape all the double quotes of the HTML code. But that's something you can decide by yourself.

User avatar
Posts: 1920
Joined: 05. March 2004 23:26
Location: Dahoim

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 92 guests