A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

Output html inside of PHP makes life easier!

985 views · started by HTML ·
#1
Output html inside of PHP makes life easier!
As you probably know, you can output PHP inside of html like so.

<html>
<title> Html and php! </title>
<body>
<?php
$Blah = true ? "blah is true" : "blah is false" ;
?>
</body>
<?php
include ("footer.php");
?>
</html>


But what about big scripts where you'll have to continuously open PHP in different areas? This could make a mess, so lets echo out HTML INSIDE of php!
<?php

echo' <html>
<title> Html and php! </title>
<body>';

$Blah = true ? "blah is true" : "blah is false" ;

include ("footer.php");
echo'</body></html>';

?>

May not look like a huge difference here, but trust me, in the long run, it will make a big difference!
#2
I thought this is how you're supposed to do it...
#3
TEMPTii wrote:
I thought this is how you're supposed to do it...


a lot of beginners don't do it this way because most books teach html outputting php first.
#4
BTW this code is not working.

original:
<?php

echo' <html>
<title> Html and php! </title>
<body>';

$Blah = true ? "blah is true" : "blah is false" ;

echo'</body>';
include ("footer.php");
</html>

?>


fixed:
<?php

echo' <html>
<title> Html and php! </title>
<body>';

$Blah = true ? "blah is true" : "blah is false" ;

include ("footer.php");
echo'</body></html>';

?>



Also, nothing is ever done with the variable Blah. Its just set, never used or echoed.
#5
Good catch I didn't see I missed the last tag. :)