Try XMLWriter ... was Re: [PHP] OO purism sucks - sell me on PHP5?
| From: | D. Dante Lorenso | Date: | Fri, 02 Jun 2006 17:04:13 +0000 |
| Subject: | Try XMLWriter ... was Re: [PHP] OO purism sucks - sell me on PHP5? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-237296@lists.php.net to get a copy of this message | ||
tg-php@gryffyndevelopment.com 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 & 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