Jump to content


This topic is now archived and is closed to further replies.

bob_the _builder

BBcode + url

Recommended Posts


When converting [url=http://tags whats the correct format:

[code=php:0]"[url]" => "<a href='",
"] tags whats the correct format:

[code=php:0]"[url]" => "<a href='",
"[/url]" => "'></a>",[/code]

how can you allow words between '> </a>

and is there security risk, should the url some how be cleaned before inserting into the database?

so far user input is been cleaned via:

[code=php:0]function ValidateInput($value) {
$value = mysql_real_escape_string(trim(strip_tags($value)));
return $value;[/code]


Share this post

Link to post
Share on other sites
function parse_url_bbcode($string)
$string = preg_replace("/\[url\](.*)\[\/url\]/","<a href='\\1'>\\1</a>",$string);
$string = preg_replace("/\[url=(.*)\](.*)\[\/url\]/","<a href='\\1'>\\2</a>",$string);
return $string;

echo parse_url_bbcode("[url=http://phpfreaks.com/forums]PHP Freaks[/url]")."<br />\n";
echo parse_url_bbcode("[url]http://phpfreaks.com[/url]");

The output would be: [code]<a href='http://phpfreaks.com/forums'>PHP Freaks</a><br />
<a href='http://phpfreaks.com'>http://phpfreaks.com</a>[/code]

Share this post

Link to post
Share on other sites

I got:

[code=php:0]$value = preg_replace("/\[url=http://(.*)\](.*)\[\/url\]/","<a href='\\1'>\\2</a>",$value);[/code]

and wrap url with:


Does the trick thanks

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.