Possible Duplicate:
Easiest way to echo HTML in PHP?
Hello,
one simple and short question. If you have a php file that contains HTML code, is it better to do the output with echo or to write the HTML code directly into the file? For example the file some.php contains either:
<div>This is a text</div><a href="www.example.com">test</a><?php if(---) { whatever; } ?>
or:
<?php echo "<div>This is a text</div><a href=\"www.example.com\">test</a>"; if(---) { whatever; } ?>
Which version is faster, cleaner and better?
In my opinion this really depends on how long the code snippet is. For simple lines I’d just use echo. For longer parts (especially with lots of ” to escape) i’d prefer “closing” the php code (your second approach).
Depending on the amount of text/HTML to print I’d also consider using some kind of simple templating engine to load a template file and just fill in dynamic variables/placeholders/gaps.