Best way to output HTML?

Best way to output HTML?

Ok, I have been told on multiple occasions that something like:

<?php if($something == $this) : ?>
<h1>Something</h1>
<?php endif; ?>

is far superior to something like:

<?php
if($something == $this)
  echo "<h1>Something</h1>";
?>

Is this true? If so why? Performance? Speed? Code Organization?

The Reddest
04/24/2009 - 10:27

This is more of a concern when dealing with the presentation layer. Most of the time, the presentation layer should just be thought of as an HTML document and should include, when at all possible, plain old HTML.

The bottom example is the opposite of this. It's a PHP script that's generating HTML.

reply

The Hairiest
04/24/2009 - 10:55

Ah, good point Red man.

reply

The Fattest
04/24/2009 - 13:57

I have to agree with you here. It is really a different feeling from the first snippet to the second.

reply

Add Comment

Put code snippets inside language tags:
[language] [/language]

Examples:
[javascript] [/javascript]
[actionscript] [/actionscript]
[csharp] [/csharp]

See here for supported languages.

Javascript must be enabled to submit anonymous comments - or you can login.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.