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
<ct:inline some="attribute">
This is an in line template. <br />
This is a #{tag} that can be accessed by the callback function
</ct:inline>
PHP/HTML: example.php
<?php
$current_dir = dirname(__FILE__).DIRECTORY_SEPARATOR;
require_once dirname($current_dir).DIRECTORY_SEPARATOR.'customtags.php';
$ct = new CustomTags(array(
'parse_on_shutdown' => true,
'tag_directory' => $current_dir.'tags'.DIRECTORY_SEPARATOR,
'sniff_for_buried_tags' => true
));
?><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Oliver Lillie">
<!-- Date: 2010-07-10 -->
</head>
<body>
<ct:youtube id="wfI0Z6YJhL0" />
</body>
</html>
Custom Tag PHP Function: tags/youtube/tag.php:
function ct_youtube($tag)
{
return '<object id="'.$tag['attributes']->id.'" value="http://www.youtube.com/v/'.$tag['attributes']->id.'" /><param ......>';
}
Output:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Oliver Lillie">
<!-- Date: 2010-07-10 -->
</head>
<body>
<object id="wfI0Z6YJhL0" value="http://www.youtube.com/v/wfI0Z6YJhL0" /><param ......>
</body>
</html>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…