我已經寫了一個類,它完全符合你對我自己的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