本帖最后由 sky94132003 于 2014-10-08 01:28:06 编辑

解决方案 »

  1.   

        private function showBBcodes($text) {
             $text = htmlspecialchars($text); //编码已存在的 HTML
             preg_match_all('#\[code\](.*?)\[/code]#is', $text, $stack);         //原来的数组赋值         $text = nl2br(preg_replace($find,$replace,$text));
             foreach($stack[1] as $t) {
               $text = preg_replsce('#\[code\].*?\[/code]#is', $t, 1); 
             }
             return $text;
        }
      

  2.   

    大哥,谢谢提醒
    竟然忘了 htmlspecialchars 
    但有关[code]
               $text = preg_replace('#\[code\].*?\#is', $t, 1); [/code]
    这样不知为什么不行,只要整篇内容有包含 [code]...就整篇内容变成 "1" 后来改成 :
               $text = preg_replace('#\[code\].*?\#is', $t, $text); [/code]改这样
    有没有什么大问题吗?
      

  3.   

    $text = preg_replsce('#\[code\].*?\[/code]#is', $t, $text, 1); 
    不好意思,写漏了
      

  4.   

    不知为什么出不了代码
    本代大哥你提供的是           $text = preg_replace('#\[code\].*?\[/code]#is', $t, 1); 
    这样不知为什么不行,只要整篇内容有包含 [code]...就整篇内容变成 "1" 要改成
               $text = preg_replace('#\[code\].*?\[/code]#is', $t, $text); 才能用请教下这样会有大问题吗?