我正在尝试制作 bbcode 系统。我想更换
[bg=color code]color text[/bg]
到
<span style="background-color:color code;">color text</span>
作者 preg_replace
.对我有什么想法吗?
最佳答案
试试下面的代码
<?php
function showBBcodes($text) {
$find = array(
'~\[background-color=(.*?)\](.*?)\[/background-color\]~s'
);
$replace = array(
'<span style="background-color:$1;">$2</span>'
);
return preg_replace($find,$replace,$text);
}
$bbtext = "[background-color=green] This is Backgroud color text [/background-color]";
$htmltext = showBBcodes($bbtext);
echo $htmltext;
?>
关于php - 如何用bb代码改变背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36785831/