Jump to content


Photo

BBcode + url


  • Please log in to reply
2 replies to this topic

#1 bob_the _builder

bob_the _builder
  • Members
  • PipPipPip
  • Advanced Member
  • 207 posts

Posted 26 September 2006 - 05:37 AM

Hi,

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

"[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;


Thanks



#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 26 September 2006 - 05:46 AM

<?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]");
?>

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


#3 bob_the _builder

bob_the _builder
  • Members
  • PipPipPip
  • Advanced Member
  • 207 posts

Posted 26 September 2006 - 07:56 AM

Hi,

I got:

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


and wrap url with:

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

Does the trick thanks





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users