It's worked great, but one thing I've always tried to figure out is how to get it to parse an http:// address to a link without the person putting the [url="http://%20tags.Well,%20I%20think%20I've%20got%20it,%20but%20it%20doesn't%20quite%20STOP%20where%20I%20want%20it%20to.
$url%20=%20"http://".$_SERVER['HTTP_HOST'];
function%20BBCode%20($string)%20{
global%20$url;
$search%20=%20array(
'@\[(?i)b\](.*?)\[/(?i)b\]@si',
'@\[(?i)i\](.*?)\[/(?i)i\]@si',
'@\[(?i)u\](.*?)\[/(?i)u\]@si',
'@\[(?i)size=(.*?)\](.*?)\[/(?i)size\]@si',
'@\[(?i)color=(.*?)\](.*?)\[/(?i)color\]@si',
'@\[(?i)center\](.*?)\[/(?i)center\]@si',
'@\[(?i)left\](.*?)\[/(?i)left\]@si',
'@\[(?i)right\](.*?)\[/(?i)right\]@si',
'@\[img\](.*?)\[/img\]@si',
'@\[(?i)url=(.*?)\](.*?)\[/(?i)url\]@si',
'@\[(?i)url\](.*?)\[/(?i)url\]@si',
[u][b]'@^(?:http://)?([^/]+)@i',[/b][/u]
'@\[(?i)bbcode\]@si'
);
$replace%20=%20array(
'<b>\\1</b>',
'<i>\\1</i>',
'<u>\\1</u>',
'<font%20style="font-size:%20\\1em;">\\2</font>',
'<font%20style="color:%20\\1;">\\2</font>',
'<center>\\1</center>',
'<p%20style="text-align:%20left;">\\1</p>',
'<p%20style="text-align:%20right;">\\1</p>',
'<img%20src="\\1"%20border="0"%20alt="User%20Image"%20/>',
'<a%20href="'.$url.'/redirect.php?url=\\1"%20target="_blank">\\2</a>',
'<a%20href="'.$url.'/redirect.php?url=\\1"%20target="_blank">\\1</a>',
[u][b]'<a%20href="'.$url.'/redirect.php?url=\\1"%20target="_blank">http://\\1</a>',[/b][/u]
);
return%20preg_replace($search%20,%20$replace,%20$string);
}
if%20(isset($_POST['submit']))%20{
$data_translated%20=%20BBCode(nl2br(htmlspecialchars(stripslashes(strip_tags($_POST['data'])))));
$pre_data%20=%20$_POST['data'];
unset($_POST['data']);
}
I%20bold%20and%20underlined%20the%202%20main%20parts.%20it%20seems%20to%20be%20adding%20a%20space%20and%20part%20of%20a%20<br%20/>%20to%20the%20link
P.S.%20%5burl="http://www.spatialvisionary.com"%5dhttp://www.spatialvisionary.com" target="_blank"> tags.
Well, I think I've got it, but it doesn't quite STOP where I want it to.
$url = "http://".$_SERVER['HTTP_HOST'];
function BBCode ($string) {
global $url;
$search = array(
'@\[(?i)b\](.*?)\[/(?i)b\]@si',
'@\[(?i)i\](.*?)\[/(?i)i\]@si',
'@\[(?i)u\](.*?)\[/(?i)u\]@si',
'@\[(?i)size=(.*?)\](.*?)\[/(?i)size\]@si',
'@\[(?i)color=(.*?)\](.*?)\[/(?i)color\]@si',
'@\[(?i)center\](.*?)\[/(?i)center\]@si',
'@\[(?i)left\](.*?)\[/(?i)left\]@si',
'@\[(?i)right\](.*?)\[/(?i)right\]@si',
'@\[img\](.*?)\[/img\]@si',
'@\[(?i)url=(.*?)\](.*?)\[/(?i)url\]@si',
'@\[(?i)url\](.*?)\[/(?i)url\]@si',
[u][b]'@^(?:http://)?([^/]+)@i',[/b][/u]
'@\[(?i)bbcode\]@si'
);
$replace = array(
'<b>\\1</b>',
'<i>\\1</i>',
'<u>\\1</u>',
'<font style="font-size: \\1em;">\\2</font>',
'<font style="color: \\1;">\\2</font>',
'<center>\\1</center>',
'<p style="text-align: left;">\\1</p>',
'<p style="text-align: right;">\\1</p>',
'<img src="\\1" border="0" alt="User Image" />',
'<a href="'.$url.'/redirect.php?url=\\1" target="_blank">\\2</a>',
'<a href="'.$url.'/redirect.php?url=\\1" target="_blank">\\1</a>',
[u][b]'<a href="'.$url.'/redirect.php?url=\\1" target="_blank">http://\\1</a>',[/b][/u]
);
return preg_replace($search , $replace, $string);
}
if (isset($_POST['submit'])) {
$data_translated = BBCode(nl2br(htmlspecialchars(stripslashes(strip_tags($_POST['data'])))));
$pre_data = $_POST['data'];
unset($_POST['data']);
}
I bold and underlined the 2 main parts. it seems to be adding a space and part of a <br /> to the link
P.S. [url="http://www.spatialvisionary.com"]http://www.spatialvisionary.com[/url] there's the working page.
Edited by SpatialVisionary, 26 June 2006 - 05:57 PM.
