I am working with a CMS for a web app in PHP, that has the needs of shortening the process for inserting (embedding) stuff, like a video from youtube or vimeo by wroting the following, which are stored in the database:
<youtube id="wfI0Z6YJhL0" />
Which would output the following after some sort of replace:
<!-- Custom formatting before object !-->
<object width="640" height="385"><param name="movie" value="http://www.youtube-nocookie.com/v/wfI0Z6YJhL0&hl=sv_SE&fs=1?rel=0&color1=0xe1600f&color2=0xfebd01"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube-nocookie.com/v/wfI0Z6YJhL0&hl=sv_SE&fs=1?rel=0&color1=0xe1600f&color2=0xfebd01" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>
<!-- Custom formatting after object !-->
How could I do this in PHP?
I'm not 100% sure how it will react to non-standard tags, but if it works, simpleHTMLDom will be perfect for this.
then something along the lines of ...
you get the drift.
The beauty of this approach would be that every specific extension could add its data in clean HTML notation
<tagname attribute="value">
, with even the possibility of adding sub-tags for structured info, instead of kludgy{placeholder}
s and regexes and so on.I have never tried this and I don't have the time to test this right now, but if you decide to give it a try, I'd be interested to know whether this way turned out to be useful.
I've written a class that does exactly what you ask for my own cms. I've uploaded the src for you as although I've never released it the source is released under a BSD style license. Custom Tags
It basically allows you do do exactly what you ask for. In the class there are some example custom tags so I won't paste code here. Let me know how you go.
Edit 1: Example Code as requested. :-)
Edit 2: I should add it supports buried custom tags.
Edit 3: It also supports inline templating and tag substitution, ie
PHP/HTML: example.php
Custom Tag PHP Function: tags/youtube/tag.php:
Output: