我已经写了一个类,它完全符合你对我自己的cms的要求。我已经为你上传了src,尽管我从未发布它,但它的源代码是在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函数:标签/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">
<!-- Date: 2010-07-10 -->
</head>
<body>
<object id="wfI0Z6YJhL0" value="http://www.youtube.com/v/wfI0Z6YJhL0" /><param ......>
</body>
</html>
取决于CMS上,以及它是否甚至支持这样的事情已经或者你就必须从头开始构建它。然而,你这样做,你可能会想使用除HTML标签分隔符之外的东西来环绕你的“标签”,否则解析和替换将会很慢。我强烈建议'']'或'{}',后者在PHP模板工具中特别常见。 – cHao 2010-07-10 16:50:52
它将全部用于自定义cms中。我正如你所说的那样,确定它可以用一些[]/{}括号来做,但我不知道如何做替换。你愿意举个例子吗? – Industrial 2010-07-10 16:56:25