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?
You should use a real parser for this, such as jBB http://jbbcode.com/