Forum Moderators: coopster

Message Too Old, No Replies

echo vs html

any advantage of echoing html as compared to closing php script

         

sneaks

5:45 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



can someone tell me if there is any obvious reason why i would want to echo html using php as compared to closing the script (?>) and then tagigng the html as per normal, opening the script again and continuing?

example one:


<div class="newsRelease">
<?php
$file="news/nr_" . $_GET[nrDate] . ".xml";
$xml = simplexml_load_file($file) or die ("Unable to load " . $file);
?>
<div class="nrDate"> <?php echo ($xml->nrDate);?> </div>
<div class="nrTitle"> <?php echo ($xml->nrTitle);?> </div>
<div class="nrBody"> <?php echo ($xml->nrBody);?> </div>
</div>

as compared to example two:


echo '<div class="newsRelease">';
$file="news/nr_" . $_GET[nrDate] . ".xml";
$xml = simplexml_load_file($file) or die ("Unable to load " . $file);
echo '<div class="nrDate">' . ($xml->nrDate) . '</div>';
echo '<div class="nrTitle">' . ($xml->nrTitle) . '</div>';
echo '<div class="nrBody">' . ($xml->nrBody) . '</div>\n</div>';

thanks & take care!
j.

jetboy_70

6:15 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



Only clarity, and your example's simple enough that there would be no gains there.

If you're using PHP to echo HTML, there's a miniscule overhead because the code is being parsed by the PHP preprocessor. However, there's also a small overhead for swapping in and out of PHP parsing! I'd stick with your usual routine unless you were embedding PHP code every few characters in a long section of HTML, where the second option might be more appropriate. The chances of that sort of scenario arising are pretty slim though.

sneaks

6:40 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



thanks jetboy!

jatar_k

1:04 am on Aug 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



also give this a read
Benchmarking PHP text output [webmasterworld.com]