bbcode解析时遇见的两个有关问题

WBOY
Release: 2016-06-13 12:07:27
Original
1153 people have browsed it

bbcode解析时遇见的两个问题!

本帖最后由 sky94132003 于 2014-10-08 01:28:06 编辑 网上一直没找到合适的bbcode解析类
所以东抄西抄的做了一个
但是出现两问题了,请各位高手协助一下。

代码在最下

问题一:bbcode解析时遇到[code][/code]不做任何处理...比如表情/其他bbcode等不转义

问题二:如何过滤HTML?
我用BBCODE保存资料就是不想用户用HTML.....

但我测试时...发现如何手动输入:
<div style="color:red">dddd</div><br />
Copy after login


竟然能真的有效


所以如果是插入一些js或者iframe应该也是可以的吧?

有什么方法可方止?

下面提供整个class 代码, 刚开始, 东抄西抄组装,还没优化好,请见谅


<br><br><?php <br />class BBCode {  <br>    public function __construct(){}<br>    private function showBBcodes($text) {<br>        // BBcode array<br>        $find = array(<br>            '~\[b\](.*?)\[/b\]~s',<br>            '~\[i\](.*?)\[/i\]~s',<br>            '~\[u\](.*?)\[/u\]~s',<br>            '~\[quote\](.*?)\[/quote\]~s',<br>            '~\[table\](.*?)\[/table\]~s',<br>            '~\[tr\](.*?)\[/tr\]~s',<br>            '~\[td\](.*?)\[/td\]~s',<br>            '~\[justify\](.*?)\[/justify\]~s',<br>            '~\[center\](.*?)\[/center\]~s',<br>            '~\[right\](.*?)\[/right\]~s',<br>            '~\[left\](.*?)\[/left\]~s',<br>            '~\[size=(.*?)\](.*?)\[/size\]~s',<br>            '~\[color=(.*?)\](.*?)\[/color\]~s',<br>            '~\[font=(.*?)\](.*?)\[/font\]~s',<br>            '~\[url=((?:ftp|https?)://.*?)\](.*?)\[/url\]~s',<br>            '~\[img\](https?://.*?\.(?:jpg|jpeg|gif|png|bmp))\[/img\]~s',<br>            '/\[img=(\d+)x(\d+)\](.*?)\[\/img\]/is',<br>            '~\[youtube\](.*?)\[/youtube\]~s',<br>        );<br><br>        // HTML tags to replace BBcode<br>        $replace = array(<br>            '<b>$1</b>',<br>            '<i>$1</i>',<br>            '<span>$1</span>',<br>            '<pre class="brush:php;toolbar:false">$1'.'pre>',<br>            '
Copy after login
$1
',
            '$1',
            '$1',
            '
$1
',
            '
$1
',
            '
$1
',
            '
$1
',
            '$2',
            '$2',
            '$2',
            '$2',
            'bbcode解析时遇见的两个有关问题',
            'bbcode解析时遇见的两个有关问题',
            ''
        );
        return nl2br(preg_replace($find,$replace,$text));
    }

    //表情转义
    private function parseSmiley($text){
        // Smiley to image
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template