2012-07-12 73 views
-1

我的一个朋友是使用BB脚本出回声正常文本BB代码。 他给了我脚本,但似乎无法理解如何让它工作。PHP BB代码以HTML脚本错误

这里是脚本

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]你好[/ B]在侧顶部的$文字和拿到剧本后没有 我赞同它,像这样

echo bb($text); 

但是我没有打印出来......如果我只是打印出$ text = $ poke1 ['status'];它将从代码打印出,但只有具有正常的文本e.g并[b]你好[/ B]

+0

你得到什么样的错误? +为什么你不要求你的朋友帮你建立他自己的代码? – Peon 2012-07-12 11:23:58

+0

我们做了一个交易脚本,针对一剧本我拿到剧本,然后他跑了......好吧,当我在这里做〔梯度= FF0000颜色= 00FF00]文本[/梯度]它只是显示的文字在这里和无颜色......即使/ * [gradient \ =“?(。*?)”?\ color =“?(。*?)”?\](。*?)\ [\/gradient \]/ms' ,我把它放在... – 2012-07-12 11:44:45

+0

问你的朋友支持,他/他写了这个脚本,所以应该知道。也知道你可以向你解释。 – hakre 2012-07-12 11:51:04

回答

0

删除或注释$text = $poke1['status'];(线4)。您正在覆盖传入该函数的数据。

前几行应该是

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

    // $text = $poke1['status']; => Commented out 
    $text = htmlspecialchars($text); 
    $text = trim($text); 
+0

Ive得到了,现在固定的几个打印功能,但它显示了在这一行$回调= create_function一个错误(“$匹配”,' $ URL = array_shift($比赛); – 2012-07-12 11:35:47

+0

请始终包含实际的错误信息,当发帖寻求帮助。 – 2012-07-12 11:38:36

+0

没有错误消息我有错误报告打开,仍然没有显示错误。当我这样做输入,比如[b]测试[/ b]它工作正常,但是当我做这样的事情[梯度= FF0000颜色= 00FF00] text here [/ gradient]它将在这里显示[gradient = FF0000 color = 00FF00]文本[/ gradient],因此脚本的一半工作正常,但中间的错误正在停止脚本的其余部分工作 – 2012-07-12 11:41:31