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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -