1

help, im trying to convert bbcode to html code , and i keep getting this error

the bbcode is [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);

after the url done, will convert the [attach]1[/attach] again by using

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

Is this the correct way to do?

Appreciate for helping.

1
  • 2
    You need to escape foreslashes / with backslashes when using a foreslash as the pattern delimiter so they read \/. Commented May 22, 2013 at 4:10

1 Answer 1

1

You have an error in your Regex. You need proper escaping for '/' character.

change this

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

to this

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

You should also change * to + because I assume you don't want to parse urls that may be empty.

Sign up to request clarification or add additional context in comments.

1 Comment

Better, i think, would be to pick a different delimiter. Past a certain point it's just easier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.