I have been working on a web application for the last 6 months and have struggled to decide between two methods of ?parsing? the html from php.
For this topic here are two methods of writing the html that are overly simplified for debate.
Method 1 (live parsing):
Code: Select all
<?php
echo '
<html>
<head>
</head>
<body>
<div id="username">
';
if( isset( $_COOKIE['username'] ) ) {
$username = $_COOKIE['username'];
echo $username;
}
echo '
</div>
</body>
</html>
';
?>
Method 2 (delayed parsing):
Code: Select all
<?php
if( isset( $_COOKIE['username'] ) ) {
$username = $_COOKIE['username'];
}
$HTML .= '
<html>
<head>
</head>
<body>
<div id="username">'. $username .'</div>
</body>
</html>
';
echo $HTML;
?>