Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Derek Sivers' Weblog:
Getting PHP To Make My HTML
May 13, 2004 @ 12:07:43

From Derek Sivers' weblog, there is a new posting about trying to convince PHP to create the basic HTML markup of strings.

He talks about some simple tags/content - things like h1, p and table tages. And, of course, each of those tags could have any of three arguments. So, he sets out to write a library of string-altering functions, using objects to contain the various bits of information. He looks at an example from the DOM class to see if something like that would work, but it just seems to inelegant for the task at hand. He decides that one effort, a few functions that, when used, would allow the coder to add attributes at will without having to greatly modify their code each time. The trick is to use a regular expression (preg_*) to grab the content inputted and make the update to the current tag - simple, right?

PHP is full of templating systems, but the idea presented here is one of the more compact, clean things I've seen to create HTML and still have the flexibility you'd need (without having to learn a sub-"scripting language" just to get a simple template made).

tagged:

Link:


Trending Topics: