这是我引用帖子的 bbcode(12345 是原始帖子的 id):
[quote=12345] ... citation ... [/quote]
我想显示这样的报价:
<blockquote>
<a href="">Username</a> at 2012-09-12 11:00 a.m. (<a href="">original</a>):
... citation ...
</blockquote>
想法(伪代码):
$bbcode_content = "[quote=12345] ... citation ... [/quote]";
// 1. get the $post_id
$post_id = replace('/\[quote\=(.*?)\]/is','$1', $bbcode_content);
// 2. select the post data from databse
$post_obj = $DB->select("SELECT `author`, `timestamp` FROM `posts` WHERE id=".$post_id);
// 3. build an extended bbcode tag
$bbcode_content = "[quote post_id={$post_id} timestamp={$post_obj->timestamp} author={$post_obj->author}]";
// 4. bbcode to html
$html = replace("[quote post_id=(*) timestamp=(*) author=(*)]", '<blockquote><a href="">$1</a> at '.date("Y-m-d h:i", $2).' (<a href="forum/post/$3">original</a>)', $bbcode_content);
$html = replace("[/quote]", "</blockquote>", $html);
问题:
- 如何递归替换这些东西?也许用preg_replace_callback?
- 我的第四点“bbcode to html”的正则表达式是什么?
我有点困惑。你会如何解决这个问题?
提前致谢!