Visit the Official PHP Website
Search this Site

PHP Programming - Lesson 1d

By James N Hitz

Yes... Now What?!

Let's fix the problem. Try this:

<html><head><title>Hello PHP World</title></head>
<body>
<?php
     print("<h2>Hello PHP World</h2>");
     echo("<hr>");
     print("<p><font size=\"3\" color=\"red\">PHP seems like fun</font></p>");
?>
</body></html>

There! Solved. All quotes WITHIN a string of text MUST be escaped. In plain English, this means that they will require to be acknowledged as quotes within quotes. This is done by preceeding them with a fore-slash: (\").

Other escapes for popular "forbidden characters" are:

Escape CodeWhat it Means
\t tab
\@ @
\n linefeed (LF or 0x0A in ASCII)
\r carriage return (CR or 0x0D in ASCII)
\t horizontal tab (HT or 0x09 in ASCII)
\\ backslash
\$ dollar sign
\" double-quote
\... and a host of others that are currently of little use to us (at least for now).

"Thank you very much Sir. BUT, do I have to escape all the text all the time? Come On. How much time of escaping do you think that will cost me...."

Enough! Escaping can be a bore. That is a fact. Especially if you have a lot of text to output. Just imagine how much escaping you will do if you wanted to produce an electronic newsletter (e-newsletter). Not a pretty site either. So?!

Enter the Here document.

<< Ambitious Alternative | The Here Document >>