用php在html页面中显示bbcode
我已经有了一个bbcode字符串用php在html页面中显示bbcode,php,bbcode,Php,Bbcode,我已经有了一个bbcode字符串$mybbcode=[b]Hello word[/b]我想用php在html页面中以html格式显示它 例如:hello word您必须使用正则表达式将BBCodes转换为HTML: 例如: $string = preg_replace('#\[b\](.+)\[\/b\]#iUs', '<b>$1</b>', $string); $string=preg\u replace(“\[b\]”(.+)\[\/b\]\iUs',“$1',$s
$mybbcode=[b]Hello word[/b]
我想用php在html页面中以html格式显示它
例如:hello word
您必须使用正则表达式将BBCodes转换为HTML: 例如:
$string = preg_replace('#\[b\](.+)\[\/b\]#iUs', '<b>$1</b>', $string);
$string=preg\u replace(“\[b\]”(.+)\[\/b\]\iUs',“$1',$string);
基本上,其他人已经跟你说过了,但如果你在谷歌搜索,你会很快看到很多关于这方面的信息,并完成了一些功能。以下是一个示例:
function bbc2html($content) {
$search = array (
'/(\[b\])(.*?)(\[\/b\])/',
'/(\[i\])(.*?)(\[\/i\])/',
'/(\[u\])(.*?)(\[\/u\])/',
'/(\[ul\])(.*?)(\[\/ul\])/',
'/(\[li\])(.*?)(\[\/li\])/',
'/(\[url=)(.*?)(\])(.*?)(\[\/url\])/',
'/(\[url\])(.*?)(\[\/url\])/'
);
$replace = array (
'<strong>$2</strong>',
'<em>$2</em>',
'<u>$2</u>',
'<ul>$2</ul>',
'<li>$2</li>',
'<a href="$2" target="_blank">$4</a>',
'<a href="$2" target="_blank">$2</a>'
);
return preg_replace($search, $replace, $content);
}
函数bbc2html($content){
$search=array(
“/(\[b\])(.*)(\[\/b\])/”,
“/(\[i\])(.*)(\[\/i\])/”,
“/(\[u\])(.*)(\[\/u\])/”,
“/(\[ul\])(.*)(\[\/ul\])/”,
“/(\[li\])(.*)(\[\/li\])/”,
“/(\[url=)(.*)(\])(.*)(.*)(\[\/url\])/”,
“/(\[url\])(.*)(\[\/url\])/”
);
$replace=数组(
“$2”,
'$2',
'$2',
“$2
”,
“2美元”,
'',
''
);
返回preg_replace($search,$replace,$content);
}
仅适用于懒惰的程序员;)
我邀请您搜索并确定已为您的项目完成的所有代码中最好的是什么。亲爱的
preg\u replace
是您需要的,请参阅或BBcode解析库,请参阅的可能副本