Simple mini-languages with PHP
I linked to PDML the other day in my blogmarks, but beyond a cursory glance I hadn’t really dug in to what makes it tick. Dumky over at Curiosity is bliss points out that it makes use of an ingenious output buffering trick. To create a PDML document, you add a single line to the top of a page that includes and executes the PDML library (written in PHP). The rest of the document is written in the custom PDML markup language. The script uses output buffering to capture the rest of the page, then executes a callback function that actually processes the page content (see ob_start() for details).
As Dumky points out, this can be used to implement mini-languages for pretty much anything—and PHP 5’s excellent XML support means most of the parser work is handled for you. It could also act as a neat way of hooking in to things like server-side XSLT processors.
Matt - 13th May 2004 00:35 - #
Matt - 13th May 2004 00:37 - #
Think Tidy fits into this as well. If you configure Apache to give old .html pages to PHP, use output buffering and Tidy and there's pretty much nothing you can't do.
Harry Fuecks - 13th May 2004 01:41 - #
Mathieu 'P 01' HENRI - 13th May 2004 01:51 - #
Hi Mathieu - exactly - have ranted about this before here. The problem I was try to solve was adding PHP manual-like user comments to generated API docs (e.g. phpDocumentor)
Harry Fuecks - 13th May 2004 02:04 - #
John Herren - 13th May 2004 06:33 - #
Manuzhai - 13th May 2004 06:42 - #
On the one hand yes but on the other, XSL-FO reminds me of a joke about asking a Yorkshire farmer for directions and getting the answer "You don't want to start from here".
I'd argue the XSL-FO is re-inventing the wheel. (X)HTML is already a good spec for marking up documents (particularily because many people know it) and it's largely possible to translate it's formatting directly to PDF. My main criticism of PDML is it adds additional tags to HTML but it's certainly going to be easier to use than XSL-FO.
Also think such "transformations" should be completely independant of source formatting syntax - it should be possible to translate RTF, Word, HTML or whatever to PDF, for example.
Harry Fuecks - 13th May 2004 08:51 - #
Manuzhai - 13th May 2004 09:48 - #
qq,q,q - 13th May 2004 14:15 - #
Even better, just turn this on for files with a .pdml extension. Then you can still use plain html for html, and if you want other prepending / appending files with PHP you can set them up to have a special file extension too.
Lach - 14th May 2004 02:33 - #
Mathieu 'P 01' HENRI - 14th May 2004 10:54 - #