前两周写了将 smilies 转换成正常图片,本想贴一下BBCode的解析,然后今天看到了有 Bulletin Board Code 解析成HTML的扩展,也就懒的翻旧账了,哈哈。
扩展地址 http://pecl.php.net/package/bbcode
还有个函数示例:
<?php
function bb_parse($string) {
$tags = 'b|i|size|color|center|quote|url|img';
while (preg_match_all('/\[('.$tags.')=?(.*?)\](.+?)\[\/\1\]/s', $string, $matches)) foreach ($matches[0] as $key => $match) {
list($tag, $param, $innertext) = array($matches[1][$key], $matches[2][$key], $matches[3][$key]);
switch ($tag) {
case 'b': $replacement = "<strong>$innertext</strong>"; break;
case 'i': $replacement = "<em>$innertext</em>"; break;
case 'size': $replacement = "<span style=\"font-size: $param;\"&g