2013-07-06 10 views
0

BB Parser를 쓰려고합니다. 내 코드는 다음과 같습니다PHP BB 코드 noparse 태그

$string = preg_replace("/\[B\](.*)\[\/B\]/Usi", "<b>\\1</b>", $string); 
$string = preg_replace("/\[I\](.*)\[\/I\]/Usi", "<i>\\1</i>", $string); 
.... 

내가 noparse 태그를 포함하고 그 문자열의 다른 태그를 구문 분석하는 부분을 건너 뛸 $ 문자열의 모든 문자열이 있는지 확인합니다. 이제 어떻게해야할지 모르겠다. 제안 사항이 있으십니까?

답변

1

이 시도 사전에 덕분에,이

<?php 
    $text = bbcode("sometext"); 
    print_r($text); 

    function bbcode($text = null) { 
    /** Replace the bbcode tags inside [noparse] to something else **/ 
    $text = preg_replace('#\[noparse\](.*)\[/noparse\]#sUe', 'noparse(\'$1\')', $text); 

    $text = preg_replace("(\[b\](.+?)\[\/b])is", '<strong>$1</strong>', $text); 
    $text = preg_replace("(\[i\](.+?)\[\/i\])is", '<em>$1</em>', $text); 
    // and so on.............. 

    /** Now restore the bbcodes tags to its original format, which we were replaced earlier **/ 
    $text = str_replace(array('*NoParse1*', '*NoParse2*'), array('[', ']'), $text); 

    return $text; 
    } 

    function noparse($text = null) { 
    $text = str_replace(array('[', ']'), array('*NoParse1*', '*NoParse2*'), $text); 
    return $text; 
    } 
?> 
+0

감사합니다 도움이되기를 바랍니다! 그것은 정말 잘 작동합니다 :) – Kable