我会将bbcode smiley转换为html标签。
转换我的代码:
function showBBcodes($text) {
// BBcode array
$find = array(
'~\[b\](.*?)\[/b\]~s',
'~\[i\](.*?)\[/i\]~s',
'~\[u\](.*?)\[/u\]~s',
'~\[del\](.*?)\[/del\]~s',
'~\[a\](.*?)\[/a\]~s',
'~\[quote\](.*?)\[/quote\]~s',
'~\[size=(.*?)\](.*?)\[/size\]~s',
'~\[color=(.*?)\](.*?)\[/color\]~s',
'~\[resim\](.*?)\[/resim\]~s',
'~\[font=(.*?)\](.*?)\[/font\]~s',
);
// HTML tags to replace BBcode
$replace = array(
'<b>$1</b>',
'<i>$1</i>',
'<span style="text-decoration:underline;">$1</span>',
'<del>$1</del>',
'<a href="$1">$1</a>',
'<pre>$1</'.'pre>',
'<span style="font-size:$1px;">$2</span>',
'<span style="color:$1;">$2</span>',
'<img src="$1">',
'<p style="font-family:$1">$2</p>',
);
// Replacing the BBcodes with corresponding HTML tags
return preg_replace($find,$replace,$text);
}
// How to use the above function:
$bbtext = filter_input(INPUT_POST, "dtext");
$htmltext = showBBcodes($bbtext);
echo $htmltext;
如你所见,它首先在变化后找到。微笑bbcode:
[:)] -> smile
[:|] -> shy
[:(] -> fury
[:o] -> swanky
[;)] -> blinking
照片:
如何显示数组中的微笑查找和替换?
我需要你的帮助。
不是:我的英语不好。