|
|
以下是我作Autolink的有效函數,在Perl(cgi)內可直接套用↓
#TYPE1
$autolink = 1;
if ($autolink) { &auto_link($FORM{'body'}); }
sub auto_link {
$_[0] =~ s/([^=^\"]|^)(http\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#\%]+)/$1<a href=\"$2\" target='_blank'>$2<\/a>/gi;
$_[0] =~ s/([^=^\"]|^)(ftp\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#\%]+)/$1<a href=\"$2\" target='_blank'>$2<\/a>/gi;
$_[0] =~ 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 {
$_[0] =~ s/([^=^\"]|^)(https?\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#\%]+)/$1<a href=\"$2\" target=\"_blank\">$2<\/a>/g;
}
#TYPE3
$_[0] =~ s/([^=^\"]|^)(http\:\/\/[\w\.\~\-\/\?\&\=\;\#\:\%\+]+\.[jJ][pP][gG])/$1<img src=\"$2\" align\=middle border\=0 >/g;
$_[0] =~ s/([^=^\"]|^)(http\:\/\/[\w\.\~\-\/\?\&\=\;\#\:\%\+]+\.[gG][iI][fF])/$1<img src=\"$2\" align\=middle border\=0 >/g;
$_[0] =~ s/([^=^\"]|^)(http\:\/\/[\w\.\~\-\/\?\&\=\;\#\:\%\+]+\.[pP][nN][gG])/$1<img src=\"$2\" align\=middle border\=0 >/g;
}
#TYPE4
&auto_link($string);
sub auto_link {
$_[0] =~ s/([^=^\"]|^)(http\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#]+)
/$1<a href=\"$2\" target=_parent>$2<\/a>/xg;
}
[ 本贴由 水電工 于 2004-7-11 22:26 最后编辑 ] |
|