PHP Code:
<?php
function ShowLinks($Text, $show=1)
{
// First match things beginning with http:// (or other protocols)
$NotAnchor = '(?<!"|href=|href\s=\s|href=\s|href\s=)';
$Protocol = '(http|ftp|https):\/\/';
$Domain = '[\w]+(.[\w]+)';
$Subdir = '([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?';
$Expr = '/' . $NotAnchor . $Protocol . $Domain . $Subdir . '/i';
if($show)
$replace = "<a href=\"$0\" title=\"$0\" target=\"_blank\">$0</a>";
else
$replace = "";
$Result = preg_replace( $Expr, $replace, $Text );
// Now match things beginning with www.
$NotAnchor = '(?<!"|href=|href\s=\s|href=\s|href\s=)';
$NotHTTP = '(?<!:\/\/)';
$Domain = 'www(.[\w]+)';
$Subdir = '([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?';
$Expr = '/' . $NotAnchor . $NotHTTP . $Domain . $Subdir . '/i';
if($show)
$replace = "<a href=\"http://$0\" title=\"http://$0\" target=\"_blank\">$0</a>";
else
$replace = "";
return preg_replace( $Expr, $replace, $Result );
}
echo ShowLinks("some www.domain.com that won't show up", 0);
echo "<br>";
echo ShowLinks("some www.domain.com that will show up");
?>
Just use it with the "0" parsed, when it has to do with text referenced within the orriginal post, and not a quoted former post within a post.