Jump to content

whats the standard for html in php?


RCB

Recommended Posts

hey guys am new to the site and to the world of php i have a pretty simple question and was wondering if someone could help...

 

 

my question is which way is better input/output html in a php file?  and is one way quicker then the other or does it if make a difference... 

 

examples:  (please keep in mind that this would be based on a much larger code then just the example)

 

1

<?php


if blah blah = blah blah {


echo <<<HTML

a bunch of blah blah html

more html
and more blah

HTML;

}else {

echo <<<HTML

else blah html

HTML;
}
?>

2:

<html>
blah blah code html

<?php
if blah blah = blah blah {
?>

blah blah html code here

<?php 
}else
{
?>

else blah blah code here

<?php
}
?>

</html>

 

thx for your help guys

RCB

Link to comment
https://forums.phpfreaks.com/topic/145302-whats-the-standard-for-html-in-php/
Share on other sites

I much prefer the second method. When I first started out, I echoed everything and as a result I'm still maintaining a really horrible nightmare app that's got echos everywhere and it's incredibly hard to follow.

 

If anything now I try to avoid putting my HTML into php logic files in the first place - I'll just use include('somehtml.php'); instead of having it all in the one file. Makes things so much easier to follow.

It depends on the circumstance.  But overall, the "standard" is to separate code from content as much as possible.  Like for instance, in your examples, you should be assigning the text to a string and passing it to a page meant only for displaying results, not mixing logic and output.  Read up on MVC (model view control).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.