[KLUG Members] PHP & HTML

bill members@kalamazoolinux.org
Thu, 19 Feb 2004 21:34:48 -0500


There's no significant speed difference doing it either way.  The 
biggest consideration is readability.  Make sure it is readable when 
you're done.

I have found that too much going in and out of HTML makes for ugly 
looking code.  It becomes hard to read and hard to find things later.

Also, when popping in and out of HTML, you tend to forget whether you're 
escaping quote marks or not:

<?php
//in php we do it like this:
echo "<p align=\"center\">hello world!</p>";
?>

<!-- while in HTML we do it like this: -->
<p align="center">hello world!</p>

Note how the quotes are escaped in PHP.

As a result, I tend to write all the code in PHP simply because that way 
I only have to remember one way of handling quote marks.  I know some of 
the page is going to be in PHP, so that's what I start with.  It has to 
be a pretty big chunk of code (probably 10 lines or more) to go back to 
HTML, and if I already wrote the first few lines in PHP I just keep going.

If it's really big HTML, I often just put it in separate file(s) and use 
includes.  Makes for ez-readin' pages that look like this:

<?php
include ("top.html"); // html

include ("thispage.php"); // programming here

include ("bottom.html"); // html

?>

kind regards,

bill


Jeremy Leonard wrote:

> What would be better practice when using php for a website?
> 
> To use html and php in the same document, switching back and forth like
> this.
> 
> HTML
> PHP
> HTML
> PHP
> HTML
> 
> Or would it be better to use all PHP in one block and in cases where you
> don't really need php just echo the html.
> 
> HTML
> PHP
> HTML
> 
> For example:
> 
> I'm building a site with some forms... duh.
> 
> Anyway...
> 
> Some of the form information is from a mysql database. I populate some
> dropdown boxes with this data.
> Should I bounce in and out of php to build this form or just do it all in
> php?
> 
> Jeremy Leonard
> 
> 
> _______________________________________________
> Members mailing list
> Members@kalamazoolinux.org
> 
> 
>