Jump to content

Archived

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

bob_the _builder

BBcode + url

Recommended Posts

Hi,

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]


Thanks

Share this post


Link to post
Share on other sites
[code]<?php
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]");
?>[/code]

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
Hi,

I got:

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


and wrap url with:

[nobbc][url=http://www.phpfreaks.com/forums/index.php?action=post;topic=109508.0;num_replies=1]phpfreaks[/url][/nobbc]

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.