Hi, Which of these is better to do? My concerns are: security, speed of execution, memory, code readability, and most important user friendliness. <?php echo '<html><body>'. $content. '<br><br>'. $footer. '</body></html>'; ?> or <html><body><?php echo $content ?><br><br><?php echo $footer ?></body></html> The first method is taking 3.1000 microseconds The second method is taking 3.6000 microseconds Thanks
There's probably not a lot in it and likely down to personal preference. I'd use the second one since it separates html as html and php as php and hence would probably be easier to debug/read in your editor.
The latter is better practice; there is no need to concatenate the strings where you are outputting completely different areas, such as HTML, the content and your footer. If you later on need to manipulate the data in some way you will, usually, have to seperate the concatentation anyway, and it makes it easier to debug if you have any problems.
The difference is not that huge. Try to keep basic HTML out of PHP code, it can cut down on what the php engine has to parse. It also keeps management of code easier. If you have to print a string with variables in it, take advantage of the sprintf and printf functions.
I find myself going with the two options below which are variations on a theme. The difference is neglible when you consider that this site is fast and it churns through a huge database load and lots of logic and output. My priorities would be towards readability and maintenance. I would, however, stress that only simple pages should work like this. All others should have some form of MVC or templating being used. Logic and presentation don't belong together. I don't see security being an issue when it comes to output, that comes earlier. <?php echo '<html><body>', $content, '<br><br>', $footer, '</body></html>'; //or echo "<html><body>{$content}<br><br>{$footer}</body></html>"; ?> PHP:
The second method is more readable but uses 2 PHP tags meaning your server would have to enter and leave the PHP engine twice. I would have to say the best practice is to use a Templating Engine like smarty or make a custom one
hiiii i think 2nd line is better in developer point of view becoz its differ both html and php i hope this will help u. thanks devid
I would go with: <html><body><?php echo $content ?><br><br><?php echo $footer ?></body></html> PHP: But modified slightly to: <html><body><?=$content?><br><br><?=$footer?></body></html> PHP: If I new for certain all servers running the php would have short tags running to avoid compatibility issues.