Reputation: 1624
I made a bbCode replacer and I got stucked with the linking.
$replacements[3] = '<a href="\1">\2</a>';
It replaces in no time, but with wrong URL... mydomain.com http:\\somelink.com\
What's wrong with this one?
Upvotes: 0
Views: 210
Reputation: 6687
You haven't actually shown the regex to match it.. but it should be something like:
Find
"'\[url=(.*?)\](.*?)\[/url\]'i"
Replace
"<a href=\"\\1\">\\2</a>"
Example
preg_replace("'\[url=(.*?)\](.*?)\[/url\]'i",
"<a href=\"\\1\">\\2</a>",
"[url=www.google.com]Google![/url]"
);
Output
<a href="www.google.com">Google!</a>
Note
I purposely don't validate the URL in the regex because it's ugly and not necessary. Validate it using filter_var(..., FILTER_VALIDATE_EMAIL);
Upvotes: 1