Best way to output HTML from PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

When I create a website in php I may have a page called products.php.
This script will contain any code required to produce a list of
products and build them into an array of objects perhaps. At the
bottom of the script I would have the following:


This page will be the HTML with embedded PHP to output the list of

<table ...>
<?php foreach($arProducts as $product): ?>
<?php endforeach; ?>

This appears very similar to something like Smarty exept I prefer to
have the use of objects and their methods when using the template.
Also I read an article on it that made a point that Smarty doesnt
really do much more than PHP as a template engine (as my above example

Now XSLT is something I dont really have a lot of practical experience
in. I know how to create an XSL file but how is it best used in PHP.
Should the XSL be used to output a whole HTML page <html>...</html> or
just simple a table or something. I would have to convert my data to
XML to perform the transformation and this just seems like an extra
process required from my own technique. XSLT has been around for a bit
now and it would seem with the added support for it in PHP5 it is very

Anyway, the point of this post is just to get peoples opinions on
outputting the front end of a page. My technique of using PHP for
templating works well for me but I may be wrong in other
circumstanses. Any guidance on this area would be much appreciated



Re: Best way to output HTML from PHP

bizt wrote:
Quoted text here. Click to load it

Not just Smarty - very common, even if you're not using templates.  I  
regularly include things like this - especially when they're being used  
on multiple pages.

Quoted text here. Click to load it

What do you need XSLT for, anyway?  Do you have a specific need?

As for what to output - it all depends on the circumstances.  If the  
code is always going to be a full page, and never have anything else on  
that page, go ahead and put the <html>...</html> code in there.  But  
that limits your reuse.

Remember - the biggest advantage of include files is reusability.  
Include too much and you limit that reusability.

Quoted text here. Click to load it

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline