自動產生連結(Auto-Link)萬用函數原始碼(Perl)
以下是我作Autolink的有效函數,在Perl(cgi)內可直接套用↓#TYPE1
$autolink = 1;
if ($autolink) { &auto_link($FORM{'body'}); }
sub auto_link {
$_ =~ s/([^=^\"]|^)(http\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#\%]+)/$1<a href=\"$2\" target='_blank'>$2<\/a>/gi;
$_ =~ s/([^=^\"]|^)(ftp\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#\%]+)/$1<a href=\"$2\" target='_blank'>$2<\/a>/gi;
$_ =~ s/([^=^\"]|^)(https\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#\%]+)/$1<a href=\"$2\" target='_blank'>$2<\/a>/gi;
}
#TYPE2
$autolink = 1;# URL地方自動聯結(0=no 1=yes)
#在您文字輸入處用
$FORM{'desc'} =~ s/\cM\n/<BR>/g;
&auto_link($FORM{'desc'}) if ($autolink);
sub auto_link {
$_ =~ s/([^=^\"]|^)(https?\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#\%]+)/$1<a href=\"$2\" target=\"_blank\">$2<\/a>/g;
}
#TYPE3
$_ =~ s/([^=^\"]|^)(http\:\/\/[\w\.\~\-\/\?\&\=\;\#\:\%\+]+\.)/$1<img src=\"$2\" align\=middle border\=0 >/g;
$_ =~ s/([^=^\"]|^)(http\:\/\/[\w\.\~\-\/\?\&\=\;\#\:\%\+]+\.)/$1<img src=\"$2\" align\=middle border\=0 >/g;
$_ =~ s/([^=^\"]|^)(http\:\/\/[\w\.\~\-\/\?\&\=\;\#\:\%\+]+\.)/$1<img src=\"$2\" align\=middle border\=0 >/g;
}
#TYPE4
&auto_link($string);
sub auto_link {
$_ =~ s/([^=^\"]|^)(http\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#]+)
/$1<a href=\"$2\" target=_parent>$2<\/a>/xg;
}
[ 本贴由 水電工 于 2004-7-1122:26 最后编辑 ]
页:
[1]