Thread: Post Hide Link
View Single Post
Old 02-12-2005, 07:05 AM   #11 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,712
redhead is on a distinguished road
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.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote