-1

我的一个朋友正在使用一个 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;
    }

所以我在顶部的 $text 中输入文本 [b] hello [/b] 并且在脚本之后什么也没有得到我像这样回显它

  echo bb($text);

但是我没有打印出来......如果我只是打印出 $text = $poke1['status']; 它会打印出来,但只有普通文本,例如 [b] hello [/b]

4

1 回答 1

0

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

前几行应该是

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

     // $text = $poke1['status']; => Commented out
     $text = htmlspecialchars($text);
     $text = trim($text);
于 2012-07-12T11:23:36.377 回答