Page 1 of 1

Embedding HTML or Dropping out of PHP?

Posted: Tue Dec 07, 2004 6:22 pm
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.

Posted: Tue Dec 07, 2004 7:14 pm
by rehfeld
theres also heredoc


Code: Select all

echo <<<EOF

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


EOF;

Posted: Tue Dec 07, 2004 7:33 pm
by andre_c
I prefer heredoc as well,
but only if I must embed html in php

Posted: Tue Dec 07, 2004 7:37 pm
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.