In a separate question here on StackOverflow (PHP library for HTML tag generation) I asked if there is a popular or standard HTML tag library for PHP.
A couple of comments showed up questioning the purpose of such a library.
Here's a bit of code from the highly acclaimed book "PHP and MySQL Web Development 4th Edition" by Luke Welling and Laura Thomson:
echo "<td width = \"".$width."%\">
<a href=\"".$url."\">
<img src=\"s-logo.gif\" alt=\"".$name."\" border=\"0\" /></a>
<a href=\"".$url."\"><span class=\"menu\">".$name."</span></a>
</td>";
I thought all the escaping and concatenating looked a little messy, so I cooked up an HTML generation library. The above looks like this using the library:
return td(array('width' => $width . '%'),
a(array('href' => $url),
img(array('src' => 's-logo.gif', 'alt' => $name, 'border' => 0))),
a(array('href' => $url), span(array('class' => 'menu'), $name)));
My question is (and keep in mind, I'm a php newb), what's the idiomatic way to write the above? Is there a cleaner way to write the book example?