Simple mini-languages with PHP
12th May 2004
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.
More recent articles
- Qwen2.5-Coder-32B is an LLM that can code well that runs on my Mac - 12th November 2024
- Visualizing local election results with Datasette, Observable and MapLibre GL - 9th November 2024
- Project: VERDAD - tracking misinformation in radio broadcasts using Gemini 1.5 - 7th November 2024