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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.