Darren
Darren

Reputation: 15

Replace [url]text[/url] BBCode placeholders with HTML hyperlinks

I have the following code:

$string = '[url]http://example.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://example.com/ that points to

mydomain.com/"http://example.com/" 

instead of

http://example.com/

How can I fix this?

Upvotes: 0

Views: 81

Answers (1)

kennytm
kennytm

Reputation: 523264

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

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

Upvotes: 3

Related Questions