[plug] Line break in HTML code
Lyndon Kroker
ljkroker at netvigator.com
Sun Aug 18 16:30:15 WST 2002
Hi Michael,
Here is some code that may help you. The following is a complete "program"
that you can run on your web server.
start of code sample...
<?php
# This small program shows two ways to output html in php.
echo "<html>\n\n";
echo "<head>\n";
echo " <title>A Sample Page</title>\n";
echo "</head>\n\n";
echo "<body bgcolor=\"white\">\n\n";
echo "<h2><font color=\"blue\">A Sample Page for Michael</font></h2>\n\n";
echo "<p>Hi Michael,</p>\n\n";
echo "<p>I thought I was the only one in the world who cared about what the
resulting html output looked like! It appears that I am mistaken. In any
case I hope that this sample code will help you to see how to make your code
look cleaner. Incidentally, the php web site <a
href=\"http://www.php.net\">php web site</a> is absolutely
fantastic!</p>\n\n";
# the following is a demonstration of what's called a 'here' document:
echo <<<EOQ
<p>I really like php. I haven't done a lot of programming and I am just
starting to get back in the swing of
things. It is amazing how much you can get done in a short time. The online
documentation is absolutly the best I have ever used.</p>
<p>Regards,</p>
<p>Lyndon :-)</p>\n\n
EOQ;
/* okay, now back to the original way...
this time all one one line
*/
echo "</body>\n\n</html>\n";
?>
end of code sample.
I have included how to use the here document format. You can get more info
on this on the php web site by searching for the echo command.
You will notice that I used \n\n to add an extra blank line. If you run the
above code and look at the output I think you will agree that it is pretty
neat.
Notice that \n is still valid in a here document. You should also note that
I have escaped occurances of the double quote within a string by using a
backslash.
Hope all this helps.
Lyndon
More information about the plug
mailing list