Try XMLWriter ... was Re: [PHP] OO purism sucks - sell me on PHP5?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



tg-php@xxxxxxxxxxxxxxxxxxxxxx wrote:
What are some of the other "killer features" of PHP5 that I may be sleeping on here.

You have got to get your hands on XMLWriter. I don't write any XHTML inside php any more. I've wrapped the XMLWriter object inside my own object and now I can create 100% properly escaped XHTML without ever using a '>' or '<' symbol:

<?php
$XML = new XTag('a', 'href', $href, 'title', 'This is a test & such.');
$XML->push('img', 'src', $img_src, 'width', 100, 'height', 50, 'border', 0);
$XML->pop(2); // img, a
print $XML->toXML();
// outputs: <a href="[$href value here]" title="This is a test &amp; such."><img src="[$img_src value here]" width="100" height="50" border="0"/></a>
?>

XMLWriter handles:

   * the escaping of characters to ensure I'm writing XHTML compliant code,
   * tags are guaranteed to open and close in the proper nested order,
   * content is encoded with UTF-8 encoding,
   * indentation of XHTML is optional
   * php code is legible without needing to backslash double and single
     quotes
   * PECL version of XMLWriter (gonna be in 5.2) contains ability to
     write raw (unescaped content) into your xml so you can merge
     already-created snippets of XHTML into your XHTML.
   * good for creating syntax valid XHTML 1.0+ strict output
   * good for creating syntax valid XML documents

There are a couple other 'gotta have' features of 5.1+ that are cool ... like PDO etc. Sadly, all that is cool appears to be cutting edge and so documentation and examples are seriously lacking. I find myself reading the source of many extensions just to try to figure out how to use them. Maybe that's a sign I'm upgrading too often? Of course, everyone is using 5.1.4 with XMLWriter from PECL, right?

Dante

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux