Jump to content

BBcode + url


bob_the _builder

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

Link to comment
https://forums.phpfreaks.com/topic/22069-bbcode-url/
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]
Link to comment
https://forums.phpfreaks.com/topic/22069-bbcode-url/#findComment-98738
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
Link to comment
https://forums.phpfreaks.com/topic/22069-bbcode-url/#findComment-98768
Share on other sites

Archived

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

×
×
  • Create New...

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.