試試這個,希望它有助於
<?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;
}
?>
謝謝!它工作得很好:) – Kable