Page 1 of 1

php mixing with html

Posted: Mon Aug 07, 2006 5:36 pm
by nincha
i notice that the recommended php.ini disable mixing html into php, for instance

Code: Select all

<?php if(){ ?> <html code> <? } else{ ?><html code> <? } ?>
what is the risk for doing this???

Posted: Mon Aug 07, 2006 5:38 pm
by Luke
makes it harder to change the user interface later... other than that... I don't think there's any problem

actually, I should mention that most good apps mix html and php, it's just to what extent is good practice

Re: php mixing with html

Posted: Mon Aug 07, 2006 5:44 pm
by Christopher
nincha wrote: what is the risk for doing this???
There is no specific security risk other than it makes it harder to see what your code is doing so perhaps a greater potential to miss problems.

Posted: Sun Aug 13, 2006 7:57 am
by AlexC
I never mix HTML with PHP, for the reason The Ninja Space Goat said, it makes it harder to change the UI later. The way I do it is use a tag replacement system / template system ( Similar to Smarty, but one I wrote my self ).

Posted: Wed Aug 16, 2006 9:53 pm
by Uranium-235
yeah, it's fine for small things, but on large scales, it just makes everything look messy

especially when it comes to forms, you might find yourself dreading large forms most when it comes to inserting HTML into your code. This is why I made a template-based form class, it makes things nicer, especially if you choose to authenticate all fields on server-side, reload all fields, and display errors. Maybe one day I'll release it

I'm sure smarty can be used for something like this, as well as other template systems.

Posted: Wed Aug 16, 2006 11:11 pm
by pedrotuga
well.. that is actualy the only way of doing dynaminc pages: generating html acording on the data and on the programming logic.

using a template sistem simply organizes things beter.... but still, the html comde has to be written somwere. no miricales.

of course its very powerfull and everything to ue a template system... but does it really worth it when developing a 1-copy aplication?

Posted: Thu Aug 17, 2006 2:37 am
by RobertGonzalez
There are good ways and bad ways of mixing PHP and HTML, whether it be through a template parser or throught native templating in PHP output. The key is mixing the two in a way that three years from now when the boss finally approves a rewrite of the presentation that the developer who is in charge of that project has some clue as to what is going on.

Code: Select all

<?php if(){ ?> <html code> <? } else{ ?><html code> <? } ?>
Could be better off as

Code: Select all

<?php if(): while()?>
<html code>
<?php endwhile; else: ?>
<html code> 
<?php endif; ?>
I added a little bit to the piece for posterity.