TRADITIONAL HTML OUTPUT FROM PHP

echo "<table cellspacing=\"0px\" cellpadding=\"0px\">\n";
echo "\t<tr>\n";
echo "\t\t<td>NW</td>\n";
echo "\t\t<td>NN</td>\n";
echo "\t\t<td>NE</td>\n";
echo "\t</tr><tr>\n";
echo "\t\t<td>WW</td>\n";
echo "\t\t<td>&nbsp;</td>\n";
echo "\t\t<td>EE</td>\n";
echo "\t</tr><tr>\n";
echo "\t\t<td>SW</td>\n";
echo "\t\t<td>SS</td>\n";
echo "\t\t<td>SE</td>\n";
echo "\t</tr>\n";
echo "</table>\n";

USING THE CLASS

require_once("htmlist.php");
 
$a = array(
	"<table cellspacing=\"0px\" cellpadding=\"0px\">",
	array(
		"<tr>",
		array(
			"<td>NW</td>",
			"<td>NN</td>",
			"<td>NE</td>"
		),
		"</tr><tr>",
		array(
			"<td>WW</td>",
			"<td>&nbsp;</td>",
			"<td>EE</td>"
		),
		"</tr><tr>",
		array(
			"<td>SW</td>",
			"<td>SS</td>",
			"<td>SE</td>"
		),
		"</tr>",
	),
	"</table>"
);
 
$b = new HTMList($a);
$b -> str(true);

ABOUT

I figured any PHP coder could use this so I decided to share, - it's a class that I use frequently in all of my PHP projects. I call it a HTMList in lack of a better name and what it does you can see above in the dreadful table example:
Have you ever tried echoing out a lot of nested html tags using PHP like for instance the table tag? You just can't avoid using an abundance of echo calls, tabs and newlines which can be frustrating and you might think that there is an easier way. Well, there is. You can put all of it in an array like I do :)

Have a download, please let me know what you think.

FEATURES

  • Clean code layout
    - Easily indent code and thus get a far more readabel source on your site
  • Extra CSS and Javascript support
    - Not only will it work similar with CSS/Javascript as HTML, - there's functions to let you omit the enclosing tags
  • Takes strings, arrays or HTMList objects as arguments
    - For maximum coding ease, you can do how you want
  • Uses a familiar syntax (arrays) with keys as labels and values as content
    - You choose a name if you want to refer to it later ( or the name will be the index number )
  • You can modify your output after defining it from anywhere
    - As opposed to echoing everything out to begin with
  • Add before, after, around and inside tags
    - Using a simple coding convention
  • All in one class written entirely in PHP
    - No configuring at all

EXAMPLES

DOWNLOAD




2010