0

我知道它有点长。我正在努力赶上最后期限,如果有人可以帮助我,我将很高兴。我的另一个朋友程序员制作了这个 PHP 脚本,但不幸的是它已经被弃用并且不起作用。任何人都可以将其转换为 preg 吗?我对eregi、preg、rejex等一无所知。

    function tolink($text){

    $text = " ".$text;

    $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',

    '<a href="\\1" target="_blank" rel="nofollow">\\1</a>', $text);

    $text = eregi_replace('(((f|ht){1}tps://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',

    '<a href="\\1" target="_blank" rel="nofollow">\\1</a>', $text);

    $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',

    '\\1<a href="http://\\2" target="_blank" rel="nofollow">\\2</a>', $text);

    $text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4})',

    '<a href="mailto:\\1"  rel="nofollow">\\1</a>', $text);

    return $text;

    }
4

1 回答 1

0

会不会是这样的

  function tolink($text){
 $text = " ".$text;
 $text = preg_replace("/(((f|ht){1}tp:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/","<a href=\"$1\" target=\"_blank\" rel=\"nofollow\">$1</a>", $text);
$text = preg_replace("/(((f|ht){1}tps:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/","<a href=\"$1\" target=\"_blank\" rel=\"nofollow\">$1</a>", $text);
 $text = preg_replace("/([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/",
                      "$1<a href=\"http://$2\" target=\"_blank\" rel=\"nofollow\">$2</a>", $text);

 $text = preg_replace('/([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4})/',
                      "<a href=\"mailto:$1\"  rel=\"nofollow\">$1</a>", $text);
 return $text;

}

您还可以i在 preg_replace 模式的末尾追加,以便匹配小写和大写字符

这就是我的意思

 preg_replace('/(((f|ht){1}tp:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i' .....
于 2012-02-19T00:38:13.297 回答