Embedding HTML or Dropping out of PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Embedding HTML or Dropping out of PHP?

Post by Benjamin »

I prefer dropping out of PHP so I don't have to worry about escaping quotes, but I was browsing the source code of phpMyAdmin and saw a cool way to embed it if needed.

Code: Select all

<?php
  $Header = ''
  . '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' . NewLine
  . '<html>' . NewLine
  . '<head>' . NewLine
  . '<title>' . $MyData['WebPageTitle'] . '</title>' . NewLine
  . '<link rel="stylesheet" type="text/css" href="style.css">' . NewLine
  . '<meta name="MSSmartTagsPreventParsing" content="true">' . NewLine
  . '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">' . NewLine
  . '</head>' . NewLine
  . '<body>' . NewLine
  . '<table cellpadding="2" cellspacing="0" border="1" width="100%">' . NewLine
  . '  <tr>' . NewLine
  . '    <td align="center">HEADER</td>' . NewLine
  . '  </tr>' . NewLine
  . '  <tr>' . NewLine
  . '    <td>' . NewLine;
?>
It works fine and looks great. Just wanted to show that to people who might not have seen that done before. What do you guys think? Also when using the constant NewLine, one get can rid of all the carriage returns to save bandwith in production mode.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

theres also heredoc


Code: Select all

echo <<<EOF

$variables will be expanded and "..'" 
 quotes dont matter "|":';';";"';'


EOF;
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

I prefer heredoc as well,
but only if I must embed html in php
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Well that is awesome, I don't recall ever seeing that used before. That is something I will definetly use in the future.
Post Reply