-1

テストテキストからbbcodeタグを削除する必要があるこのbbcodeタグ「リムーバー」があります。私が得るのは何もありません。テキストをhtmlタグに置き換える必要がある空白のページ。どうしたの。そして、共有するより良いスクリプトを誰かが持っているかもしれません。

$str = 'This [b]is just[/b] a [i]test[/i] text!';
function forum_text($str)
{
$str = htmlspecialchars($str);

$str = preg_replace( "#\[url\](?:http:\/\/)?(.+?)\[/url\]#is", "<a href=\"http://$1\">$1</a>", $str ); 
$str = preg_replace( "#\[img\](?:http:\/\/)?(.+?)\[/img\]#is", "<img src=\"http://$1\" />", $str ); 
$str = preg_replace( "#\[b\](.+?)\[/b\]#is", "<strong>$1</strong>", $str ); 
$str = preg_replace( "#\[i\](.+?)\[/i\]#is", "<i>$1</i>", $str ); 
$str = preg_replace( "#\[u\](.+?)\[/u\]#is", "<u>$1</u>", $str ); 

return $str;
}
4

1 に答える 1

0

The following is your code, with some code in front of it (to make sure any errors are shown) and some code at the back (that actually calls your function).

If this doesn't work for you, your problem is not here, unless you don't have a working PCRE.

error_reporting(-1); ini_set('display_errors', 'On');

$str = 'This [b]is just[/b] a [i]test[/i] text!';
function forum_text($str)
{

    $str = htmlspecialchars($str);

    $str = preg_replace( "#\[url\](?:http:\/\/)?(.+?)\[/url\]#is", "<a href=\"http://$1\">$1</a>", $str );
    $str = preg_replace( "#\[img\](?:http:\/\/)?(.+?)\[/img\]#is", "<img src=\"http://$1\" />", $str );
    $str = preg_replace( "#\[b\](.+?)\[/b\]#is", "<strong>$1</strong>", $str );
    $str = preg_replace( "#\[i\](.+?)\[/i\]#is", "<i>$1</i>", $str );
    $str = preg_replace( "#\[u\](.+?)\[/u\]#is", "<u>$1</u>", $str );

    return $str;
}

echo forum_text($str);
于 2012-08-27T18:51:55.390 に答える