2012-07-12 8 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']; [b] hello [/ b]

+0

해야 하는가? + 자신의 코드를 설정하도록 친구에게 요청하는 것이 어떻습니까? – Peon

+0

우리는 스크립트 스크립트를 가지고 스크립트를 만들었습니다. 스크립트를 실행했을 때 ... 그라디언트 = FF0000 컬러 = 00FF00] 텍스트를 여기 [그라디언트]로 입력하면 여기에 텍스트와 색상이 표시됩니다 ... 심지어 (\ *)? \ (그라디언트 \]/ms ') *? \] (. *?) "? \] , 나는 그것을 deffine ... –

+0

친구에게 지원을 요청, 그/그 스크립트를 썼다 그래서 알아야한다. 또한 당신을 알고 당신에게 설명 할 수 있습니다. – hakre

답변

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 이제 수정 된 것이 있지만이 줄에는 오류가 표시됩니다. $ callback = create_function ('$ matches', ' $ url = array_shift ($ matches); –

+0

언제든지 실제 오류 메시지를 포함하십시오. –

+0

오류 메시지가 표시되지 않습니다. 오류보고 기능이 켜져 있는데도 오류가 표시되지 않습니다. [b] test [/ b]와 같은 입력을 할 때 제대로 작동하지만 [gradient = FF0000 color = 00FF00] 여기에 텍스트 [/ 그라디언트] 그냥 그라디언트 = FF0000 색상 = 00FF00] 텍스트를 여기에 표시됩니다 [/ 그라데이션] 그래서 스크립트의 절반은 작동하지만 중간에 오류가 스크립트의 나머지 작업을 중지합니다 –