-1

So I've looked everywhere for how to do this, and I've found a few threads, but none have helped me... I understand /how/ to replace it in general, but this example is odd (not my code, I took over from someone else), so I'm not sure how to replace it without it giving me errors everywhere.

One of the examples is this:

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

This is within a function, which converts $content to a BB_Code. I've tried the following:

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

But it throws me an "unknown modifier" in 'r' error. Also 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 this is a bad question, but I'm just trying to understand fully how to replace this so I can fix the syntax...

Thanks for any help though!

1 Answers1

0

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

Just escape the / before url:

\\[url=([^\\[]*)\\]([^\\[]*)\\[\\/url\\]
Anonymous
  • 11,748
  • 6
  • 35
  • 57