Jump to content

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).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.