1

助けて、bbcode を html コードに変換しようとしていますが、このエラーが発生し続けます

BBコードは[url=link][attach]1[/attach][/url]

SCREAM: Error suppression ignored for( ! ) Warning: preg_replace(): Unknown modifier '/'

        $content = $getThread['message'];
        $bbUrl = '/\[url=(http|https|ftp)://{1}([a-zA-Z0-9/%@?:#&+._=-]*)\](.*?)\[/url\]/gixsm';
        $htmlUrl = '<a href="{$1}://{$2}" target="_blank">{$3}</a>';
        $atable = $thread->get_atable($tid);
        $content = preg_replace($bbUrl, $htmlUrl, $content);

URLが完了したら、[attach]1[/attach]を使用して再度変換します

$bbAttachment = 'etc...';
$htmlAttachment = 'etc...';
$content = preg_replace($bbAttachment, $htmlAttachment , $content);

これは正しい方法ですか?

助けてくれてありがとう。

4

1 に答える 1

1

正規表現にエラーがあります。「/」文字には適切なエスケープが必要です。

これを変える

 $bbUrl = '/\[url=(http|https|ftp)://{1}([a-zA-Z0-9/%@?:#&+._=-]*)\](.*?)\[/url\]/gixsm';

これに

 $bbUrl = '/\[url=(http|https|ftp):\/\/([a-zA-Z0-9\/%@?:#&+._=-]+)\](.+?)\[\/url\]/gixsm';

また、空の可能性のある URL を解析したくないと想定しているため、 に 変更*する必要があります。+

于 2013-05-22T04:58:24.983 に答える