php - Replacing eregi_replace with preg_replace -


so i've looked everywhere how this, , i've found few threads, none have helped me... understand /how/ replace in general, example odd (not code, took on else), i'm not sure how replace without giving me errors everywhere.

one of examples this:

$content = eregi_replace("\\[url=([^\\[]*)\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=_blank>\\2</a>",$content); 

this within function, converts $content bb_code. i've tried following:

$content = preg_replace('/[url=([^\\[]*)\\]([^\\[]*)\\[/url\\]/i','<a href=\"\\1\" target=_blank>\\2</a>',$content); 

but throws me "unknown modifier" in 'r' error. tried

    $content = preg_replace('/[url=([^[]*)]([^[]*)[/url]/i','<a href=\"\\1\" target=_blank>\\2</a>',$content); 

but again, unknown modifier in 'r'.

i'm sorry if bad question, i'm trying understand how replace can fix syntax...

thanks though!

you've been trying remove wrong kind of slashes. need remove forward slashes (/) instead of backslashes (\) since / marks end of regular expression.

just escape / before url:

\\[url=([^\\[]*)\\]([^\\[]*)\\[\\/url\\] 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -