tags:

views:

31

answers:

1

Hello,

I have the following code:

$string = '[url]http://google.com[/url]';
$bbreplace = array ('/\[url\](.+?)\[\/url\]/');
$bbreplacements = array ('<a href=\"\\1\">\\1</a>');
$string = preg_replace($bbreplace, $bbreplacements, $string);
print $string;

Which creates a url called http://google.com/ that points to

mydomain.com/"http://google.com/" 

instead of

http://google.com/

How can I fix this? Thanks

+3  A: 

You don't need to escape the " inside '.

$bbreplacements = array ('<a href="\\1">\\1</a>');

(BTW, use a BBcode parser.)

KennyTM
Do they need to be `$1` ?
alex
@alex: Both `\1` and `$1` work.
KennyTM
thanks for the help
Darren
@KennyTM Thanks, I learned something.
alex