Reputation: 33
I have a little script here which replaces BB code with HTML code. Everything works fine but the URLs.
$bbextended = array(
"/\[URL=(.*?)\](.*?)\[\/URL\]/i" => "<a href=\"$1\" title=\"$1\">$2</a>"
);
foreach($bbextended as $match=>$replacement){
$bbtext = preg_replace($match, $replacement, $bbtext);
}
Input
[URL="http://somewebsite.come/something"]Some Website Title[/URL]
Output
<a href=""http://somewebsite.come/something"" title=""http://somewebsite.come/something"">Some Website Title</a>
There are double-quotes, which obviously isn't that good.
I tried
$bbextended = array(
"/\[URL=\"(.*?)\"\](.*?)\[\/URL\]/i" => "<a href=\"$1\" title=\"$1\">$2</a>"
);
in the code but it didn't work. I also tried to leave out the escape sign and quotes around the $1
in the HTML code but it didn't work neither.
Any ideas?
Upvotes: 0
Views: 691
Reputation:
When I
Set the Find string = '/\[URL="(.*?)"\](.*?)\[\/URL\]/i'
and
Set the replace string = '<a href="$1" title="$1">$2</a>'
I get this using simple preg_replace
<a href="http://somewebsite.come/something" title="http://somewebsite.come/something">Some Website Title</a>
Upvotes: 0
Reputation: 48111
You should use a real parser for this, such as jBB http://jbbcode.com/
Upvotes: 1