如何修复聊天中显示笑脸以及用星号替换脏话的小错误?
嘿大家好,我的网站有一个聊天框,并且已经内置了笑脸功能,但是没有“诅咒过滤器”,所以我决定今天尝试添加它。这是聊天框的输出:
$return .= "<div style=\"font-size: 14px; padding-bottom: 3px; color: #444444;\">". $time . $icon . $username . str_replace('"', "'", parse_bbcode(smiley(str_replace("\n", '', $chat['text'])))) ."</div>";
在接近尾声时显示:
str_replace('"', "'", parse_bbcode(smiley(str_replace("\n", '', $chat['text']))))
我已经用诅咒替换了笑脸只是为了测试它,并且诅咒功能完美地工作,但我想知道如何同时获得笑脸和诅咒要显示的功能,而不是仅显示其中之一。
我已经尝试过:
parse_bbcode(smiley, curses
parse_bbcode(smiley . curses
但没有运气......
这是我的 parse_bbcode 函数:
function parse_bbcode($text, $xhtml = true) {
$tags = array(
'#\[b\](.*?)\[/b\]#si' => ($xhtml ? '<strong>\\1</strong>' : '<b>\\1</b>'),
'#\[i\](.*?)\[/i\]#si' => ($xhtml ? '<em>\\1</em>' : '<i>\\1</i>'),
'#\[u\](.*?)\[/u\]#si' => ($xhtml ? '<span style="text-decoration: underline;">\\1</span>' : '<u>\\1</u>'),
'#\[s\](.*?)\[/s\]#si' => ($xhtml ? '<strike>\\1</strike>' : '<s>\\1</s>'),
'#\[color=(.*?)\](.*?)\[/color\]#si' => ($xhtml ? '<span style="color: \\1;">\\2</span>' : '<font color="\\1">\\2</font>'),
'#\[img\](.*?)\[/img\]#si' => ($xhtml ? '<img src="\\1" border="0" alt="" style="max-width: 400px; max-height: 200px;" />' : '<img src="\\1" border="0" alt="">'),
'#\[url=(.*?)\](.*?)\[/url\]#si' => '<a href="\\1" target="_blank" style="color: #000000; font-size: 12px;" title="\\2">\\2</a>',
'#\[email\](.*?)\[/email\]#si' => '<a href="mailto:\\1" title="Email \\1">\\1</a>',
'#\[code\](.*?)\[/code\]#si' => '<code>\\1</code>',
'#\[align=(.*?)\](.*?)\[/align\]#si' => ($xhtml ? '<div style="text-align: \\1;">\\2</div>' : '<div align="\\1">\\2</div>'),
'#\[br\]#si' => ($xhtml ? '<br style="clear: both;" />' : '<br>'),
);
foreach ($tags AS $search => $replace) {
$text = preg_replace($search, $replace, $text);
}
return $text;
}
Hey all so I have a chat box for my site and there was already a smileys feature built into it, however there was no "curse filter" so I decided I would try and add that today. This is the output of the chat box:
$return .= "<div style=\"font-size: 14px; padding-bottom: 3px; color: #444444;\">". $time . $icon . $username . str_replace('"', "'", parse_bbcode(smiley(str_replace("\n", '', $chat['text'])))) ."</div>";
Near the end of that it shows:
str_replace('"', "'", parse_bbcode(smiley(str_replace("\n", '', $chat['text']))))
I have replaced smiley with curses just to test it out, and the curses function works perfectly, but I'm wondering how I can get both the smiley AND curses functions to display, instead of just one or the other.
I've tried:
parse_bbcode(smiley, curses
parse_bbcode(smiley . curses
but have had no luck....
Here is my parse_bbcode function:
function parse_bbcode($text, $xhtml = true) {
$tags = array(
'#\[b\](.*?)\[/b\]#si' => ($xhtml ? '<strong>\\1</strong>' : '<b>\\1</b>'),
'#\[i\](.*?)\[/i\]#si' => ($xhtml ? '<em>\\1</em>' : '<i>\\1</i>'),
'#\[u\](.*?)\[/u\]#si' => ($xhtml ? '<span style="text-decoration: underline;">\\1</span>' : '<u>\\1</u>'),
'#\[s\](.*?)\[/s\]#si' => ($xhtml ? '<strike>\\1</strike>' : '<s>\\1</s>'),
'#\[color=(.*?)\](.*?)\[/color\]#si' => ($xhtml ? '<span style="color: \\1;">\\2</span>' : '<font color="\\1">\\2</font>'),
'#\[img\](.*?)\[/img\]#si' => ($xhtml ? '<img src="\\1" border="0" alt="" style="max-width: 400px; max-height: 200px;" />' : '<img src="\\1" border="0" alt="">'),
'#\[url=(.*?)\](.*?)\[/url\]#si' => '<a href="\\1" target="_blank" style="color: #000000; font-size: 12px;" title="\\2">\\2</a>',
'#\[email\](.*?)\[/email\]#si' => '<a href="mailto:\\1" title="Email \\1">\\1</a>',
'#\[code\](.*?)\[/code\]#si' => '<code>\\1</code>',
'#\[align=(.*?)\](.*?)\[/align\]#si' => ($xhtml ? '<div style="text-align: \\1;">\\2</div>' : '<div align="\\1">\\2</div>'),
'#\[br\]#si' => ($xhtml ? '<br style="clear: both;" />' : '<br>'),
);
foreach ($tags AS $search => $replace) {
$text = preg_replace($search, $replace, $text);
}
return $text;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哦天哪...
Oh my...