As you have seen PHP recognises variable names inside quoted text.  However sometimes you might want to use the dollar symbol ($) as currency not as a variable name or quotes as speech marks and not to hold string literals.  You might also want to use quotation marks within the text.  As an example create a new page called phpescape.php and place this in the lower block of PHP under the h1:

$both="This $stockitemname is worth $thirty to which you might say "Wow, cheap".";
echo $both;

The string is being put into a variable and then displayed to the user.  What you want to be displayed is this:

This skateboard is worth $thirty to which you might say "Wow, cheap".

Try it and you should get errors.  Within that string are two main problems for PHP:

The first error may be fairly rare but the second is very common so get used to it.  The fix is the same for both.


To fix the common problem first you need to escape the quotes which you want treated as part of the text and not the PHP:

$both="This $stockitemname is worth $thirty to which you might say \"Wow, cheap\".";

Save it and try it.  Now the script works but with a notice which we fix next.

Other special symbols

Escape the dollar sign the way you did the quotes:

$both="This $stockitemname is worth \$thirty to which you might say \"Wow, cheap\".";

Try it and it should work now.  Escaping is saying "The next character is text not part of the PHP code so just display it".  You might also need to to escape braces and other characters with special meaning in PHP as you come across them.  Watch out for "Unexpected" in error messages.  You have either missed out quotes (semi-colons) or you have special characters in your strings.