0

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?

2 Answers 2

1

You should use a real parser for this, such as jBB http://jbbcode.com/

Sign up to request clarification or add additional context in comments.

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.