-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;
    }

だから私はテキスト[b]hello[/b]を上部の$textの横に入力し、スクリプトの後に何も取得しません。

  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 に答える