PHP BB代码到HTML脚本错误

PHP BB代码到HTML脚本错误,php,html,bbcode,Php,Html,Bbcode,我的一个朋友正在使用一个bb脚本,它将普通文本回送到bb代码中。 他给了我剧本,但似乎不明白如何让它发挥作用 这是剧本 define ("EMOTICONS_DIR", "img/smilies/"); function bb($text) { $text = $poke1['status']; $text = htmlspecialchars($text); $text = trim($text); if (!functi

我的一个朋友正在使用一个bb脚本,它将普通文本回送到bb代码中。 他给了我剧本,但似乎不明白如何让它发挥作用

这是剧本

    define ("EMOTICONS_DIR", "img/smilies/");
    function bb($text) {

  $text = $poke1['status'];
        $text = htmlspecialchars($text);
        $text = trim($text);

        if (!function_exists('escape')) {
            function escape($s) {
                global $text;
                $text = strip_tags($text);
                $code = $s[1];
                $code = htmlspecialchars($code);
                $code = str_replace("[", "[", $code);
                $code = str_replace("]", "]", $code);
                return '<pre><code>'.$code.'</code></pre>';
            }   
        }
       $pattern  = '#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#';
       $callback = create_function('$matches', '
           $url = array_shift($matches);

           $text = preg_replace("/^www./", "", $text);
           $text = $url;

    if (preg_match("/\[/i", $url) || preg_match("/\]/i", $url)) {
    return($url);
    }else{
    return sprintf(\'<a href="%s" target="_blank" rel="nofollow">%s</a>\', $url, $text);
    }
       ');

    $text = preg_replace_callback($pattern, $callback, $text);



        $text = preg_replace_callback('/\[code\](.*?)\[\/code\]/ms', "escape", $text);


        // Smileys to find...
        $in = array(                 ":3:",     
                         ":@",
                         ":bad:",
                         ":'(",
                         ":eee:",
                         ":error:",
                         ":excited:",
                         ":explode:",
                         ":hey:",
                         ":lol:",
                         ":love:",
                         ":magikarp:",
                         ":ohnoes:",
                         ":oo:",
                         ":pika:",
                         ":(",
                         ":suck:",
                         ":loo:",
                         ";)",
                         ":wobby:",
                         ":wobby2:",
                         ":woo:",
                         ":wtf:",
                         ":yes:",
                         "viewform?formkey=",
                         "google.com/spreadsheet/",
                         "tpsrpgo","tpmrpg","pkmnmoon","pokemonvortex","weebly","nsigma",
                         "amp;"
        );
        // And replace them by...
        $out = array(            '<img src="'.EMOTICONS_DIR.'3.gif" />',
                         '<img src="'.EMOTICONS_DIR.'angry.gif" />',
                         '<img src="'.EMOTICONS_DIR.'bad.gif" />',
                         '<img src="'.EMOTICONS_DIR.'cry.gif" />',
                         '<img src="'.EMOTICONS_DIR.'eee.gif" />',
                         '<img src="'.EMOTICONS_DIR.'error.gif" />',
                         '<img src="'.EMOTICONS_DIR.'excited.gif" />',
                         '<img src="'.EMOTICONS_DIR.'explode.gif" />',
                         '<img src="'.EMOTICONS_DIR.'hey.gif" />',
                         '<img src="'.EMOTICONS_DIR.'lol.gif" />',
                         '<img src="'.EMOTICONS_DIR.'love.gif" />',
                         '<img src="'.EMOTICONS_DIR.'magikarp.gif" />',
                         '<img src="'.EMOTICONS_DIR.'noo.gif" />',
                         '<img src="'.EMOTICONS_DIR.'oo.gif" />',
                         '<img src="'.EMOTICONS_DIR.'pikapika.gif" />',
                         '<img src="'.EMOTICONS_DIR.'sad.gif" />',
                         '<img src="'.EMOTICONS_DIR.'suck.gif" />',
                         '<img src="'.EMOTICONS_DIR.'toilet.gif" />',
                         '<img src="'.EMOTICONS_DIR.'wink.gif" />',
                         '<img src="'.EMOTICONS_DIR.'wobby.gif" />',
                         '<img src="'.EMOTICONS_DIR.'wobby2.gif" />',
                         '<img src="'.EMOTICONS_DIR.'woo.gif" />',
                         '<img src="'.EMOTICONS_DIR.'wtf.gif" />',
                         '<img src="'.EMOTICONS_DIR.'yes.gif" />',
                         '<b><br>Ignore and report this message to Da Man!</b><br><br>',
                         '<b><br>Ignore and report this message to Da Man!</b><br><br>',
                         'lol','lol','lol','lol','lol','lol',
                         ''
    );
        $text = str_replace($in, $out, $text);

        // BBCode to find...
        $in = array(     '/\[b\](.*?)\[\/b\]/ms',   
                         '/\[B\](.*?)\[\/B\]/ms',
                         '/\[i\](.*?)\[\/i\]/i',
                         '/\[u\](.*?)\[\/u\]/i',
                         '/\[img\](.*?)\[\/img\]/i',
                         '/\[url\="?(.*?)"?\](.*?)\[\/url\]/ms',
                         '/\[size\=xx-small\](.*?)\[\/size\]/ms',
                         '/\[size\=x-small\](.*?)\[\/size\]/ms',
                         '/\[size\=small\](.*?)\[\/size\]/ms',
                         '/\[size\=medium\](.*?)\[\/size\]/ms',
                         '/\[size\=large\](.*?)\[\/size\]/ms',
                         '/\[size\=x-large\](.*?)\[\/size\]/ms',
                         '/\[size\=xx-large\](.*?)\[\/size\]/ms',
                         '/\[color\="?(.*?)"?\](.*?)\[\/color\]/ms',
                         '/\[gradient\="?(.*?)"?\ color="?(.*?)"?\](.*?)\[\/gradient\]/ms',
                         '/\[font\="?(.*?)"?\](.*?)\[\/font\]/ms',
                         '/\[align\="?(.*?)"?\](.*?)\[\/align\]/ms',
                         '/\[quote\="?(.*?)"?\ id="?(.*?)"?\ dateline="?(.*?)"?\ pid="?(.*?)"?\](.*?)\[\/quote\]/ms',
                         '/\[quote\](.*?)\[\/quote\]/ms',
                         '/\[youtube\](.*?)\[\/youtube\]/ms',
                         '/\[list\=(.*?)\](.*?)\[\/list\]/ms',
                         '/\[list\](.*?)\[\/list\]/ms',
                         '/\[\*\]\s?(.*?)\n/ms'

        );
        // And replace them by...
        $out = array(    '<strong>\1</strong>',
                         '<strong>\1</strong>',
                         '<em>\1</em>',
                         '<u>\1</u>',
                         '<img src="\1" alt="\1" />',
                         '<a href="\1" rel="nofollow">\2</a>',
                         '<font size="1">\1</font>',
                         '<font size="2">\1</font>',
                         '<font size="3">\1</font>',
                         '<font size="4">\1</font>',
                         '<font size="5">\1</font>',
                         '<font size="6">\1</font>',
                         '<font size="7">\1</font>',
                         '<font color="\1">\2</font>',
                         '<span class="gradient#\1#\2">\3</span>',
                         '<font face="\1">\2</font>',
                         '<div align="\1">\2</div>',
    '<blockquote><cite><span>\3</span>\1 Wrote: <a href="viewthread.php?id=\2#\4" class="quick_jump" rel="nofollow">&nbsp;</a></cite>\5</blockquote>',
                         '<blockquote>\1</blockquote>',
    '<object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/\1&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/$1&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="320"></embed></object>',
                         '<ol start="\1">\2</ol>',
                         '<ul>\1</ul>',
                         '<li>\1</li>',
        );

        $text = preg_replace($in, $out, $text);

        // paragraphs
        $text = str_replace("\r", "", $text);


        // clean some tags to remain strict
        // not very elegant, but it works. No time to do better ;)
        if (!function_exists('removeBr')) {
            function removeBr($s) {
                return str_replace("<br />", "", $s[0]);
            }
        }   
        $text = preg_replace_callback('/<pre>(.*?)<\/pre>/ms', "removeBr", $text);
        $text = preg_replace('/<p><pre>(.*?)<\/pre><\/p>/ms', "<pre>\\1</pre>", $text);

        $text = preg_replace_callback('/<ul>(.*?)<\/ul>/ms', "removeBr", $text);
        $text = preg_replace('/<p><ul>(.*?)<\/ul><\/p>/ms', "<ul>\\1</ul>", $text);

        $text = nl2br($text);
        $text = stripslashes($text);
        return $text;
    }
'; } } $pattern='#\b(([\w-]+:/?| www[.])[^\s()]+(?:\([\w\d]+\)|([^[:punct:][\s]|/))); $callback=create_函数('$matches',' $url=数组移位($matches); $text=preg_replace(“/^www./”,“”,$text); $text=$url; if(preg_match(“/\[/i”,$url)| preg_match(“/\]/i”,$url)){ 返回($url); }否则{ 返回sprintf(\'\',$url,$text); } '); $text=preg\u replace\u回调($pattern,$callback,$text); $text=preg\u replace\u回调('/\[code\](.*?\[\/code\]/ms',“escape”,$text); //微笑寻找。。。 $in=数组(“:3:”, ":@", “:坏:”, ":'(", “:eee:”, “:错误:”, “:兴奋:”, “:爆炸:”, “:嘿:”, “:lol:”, “:爱:”, “:magikarp:”, “:ohnoes:”, “:oo:”, “:鼠兔:”, ":(", “:吸:”, “:loo:”, ";)", “:沃比:”, “:沃比2:”, “:呜:”, “:wtf:”, “:是:”, “viewform?formkey=“, “google.com/spreadsheet/”, “tpsrpgo”、“tpmrpg”、“pkmnmoon”、“口袋妖怪”、“weebly”、“nsigma”, “amp;” ); //并用…取代它们。。。 $out=数组(“”, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', “
忽略此消息并将其报告给Da Man!

”, “
忽略此消息并将其报告给Da Man!

”, ‘lol’、‘lol’、‘lol’、‘lol’、‘lol’、‘lol’、‘lol’, '' ); $text=str_replace($in,$out,$text); //要查找的BBCode。。。 $in=数组('/\[b\](.*?\[\/b\]/ms', “/\[B\](.*?\[\/B\]/ms”, “/\[i\](.*?\[\/i\]/i”, “/\[u\](.*?\[\/u\]/i”, “/\[img\](.*?\[\/img\]/i”, “/\[url\=”?(.*?)?\](.*?)\[\/url\]/ms”, “/\[size\=xx小\](.*?\[\/size\]/ms”, “/\[size\=x-small\](.*?\[\/size\]/ms”, “/\[size\=small\](.*?\[\/size\]/ms”, “/\[size\=medium\](.*?\[\/size\]/ms”, “/\[size\=large\](.*?\[\/size\]/ms”, “/\[size\=x-large\](.*?\[\/size\]/ms”, “/\[size\=xx大\](.*?\[\/size\]/ms”, “/\[color\=”?(.*??“?”)(.*?\[\/color\]/ms”, “/\[gradient\=”?(.*?)“\color=“?(.*?)?”\](.*?)\[\/gradient\]/ms”, “/\[font\=”?(.*?)?\](.*?)\[\/font\]/ms”, “/\[align\=”?(.*??“?”)(.*?\[\/align\]/ms', “/\[quote\=”?(.*?)“\id=“?(.*?”)\dateline=“?(.*?)”\pid=“?(.*?)?”?(.*?)“\]”(.*?)[\/quote\]/ms', “/\[quote\](.*?\[\/quote\]/ms”, “/\[youtube\](.*?\[\/youtube\]/ms”, “/\[list\=(.*?\](.*?\[\/list\]/ms”, “/\[list\](.*?\[\/list\]/ms”, '/\[\*\]\s?(.*)\n/ms' ); //并用…取代它们。。。 $out=数组(“\1”, “\1”, '\1', '\1', '', '', '\1', '\1', '\1', '\1', '\1', '\1', '\1', '\2', '\3', '\2', '\2', “\3\1写入:\5”, '\1', '', '\2', “
    \1
”, “
  • \1
  • ”, ); $text=preg_replace($in,$out,$text); //段落 $text=str\u replace(“\r”,”,$text); //清理一些标签以保持严格 //不是很优雅,但很有效。没有时间做得更好;) 如果(!function_存在('removeBr')){ 函数移除br($s){ 返回str_replace(“
    ,”“,$s[0]); } } $text=preg\u replace\u回调('/
    但是我没有打印出来…如果我只是打印出$text=$poke1['status'],它将打印出来,但只有普通文本,例如[b]hello[/b]

    从代码中删除或注释
    $text=$poke1['status'];
    (第4行)。您正在覆盖传递到函数中的数据

    前几行
      echo bb($text);
    
    define ("EMOTICONS_DIR", "img/smilies/");
    function bb($text) {
    
         // $text = $poke1['status']; => Commented out
         $text = htmlspecialchars($text);
         $text = trim($text);