我已经为自己的CMS编写了一个类,可以完全满足您的需求。尽管我从未发布过它,但我已经将源代码发布在BSD风格许可下。
Custom Tags
它基本上允许您按照您所要求的方式进行操作。在类中有一些示例自定义标记,因此我不会在此处粘贴代码。告诉我您的进展如何。
编辑1:示例代码如请求的那样。 :-)
编辑2:我应该补充说明它支持嵌套的自定义标记。
编辑3:它还支持内联模板和标记替换,例如
<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>
自定义标签 PHP 函数:tags/youtube/tag.php:
function ct_youtube($tag)
{
return '<object id="'.$tag['attributes']->id.'" value="http://www.youtube.com/v/'.$tag['attributes']->id.'" /><param ......>';
}
输出:
<!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">
</head>
<body>
<object id="wfI0Z6YJhL0" value="http://www.youtube.com/v/wfI0Z6YJhL0" /><param ......>
</body>
</html>
[]
或{}
,后者在PHP模板工具中尤其常见。 - cHao