du4010 2018-02-18 07:15
浏览 78

将微笑bbcode转换为html标签

i would convert bbcode smiley to html tag.

For convert i fid this code :

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;

As you see first it find after change. Smile bbcode :

[:)] -> smile
[:|] -> shy
[:(] -> fury
[:o] -> swanky
[;)] -> blinking

Photos :

smileshyfuryswankyblinking

How show the smiles in array find and replace?

I need your help.

Not : I don't have a good English.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥20 使用Photon PUN2解决游戏得分同步的问题
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM