代码如下:
<?php /** * php正则判断url 自动转换为超链接 * site: www.jb200.com */ function autolink($foo) { $foo = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_/+.~#?&//=]+)', '<a href="/1" mce_href="/1" target=_blank rel=nofollow>/1</a>', $foo); if( strpos($foo, "http") === FALSE ){ $foo = eregi_replace('(www.[-a-zA-Z0-9@:%_/+.~#?&//=]+)', '<a href="http:///1" mce_href="http:///1" target=_blank rel=nofollow >/1</a>', $foo); }else{ $foo = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_/+.~#?&//=]+)', '/1<a href="http:///2" mce_href="http:///2" target=_blank rel=nofollow >/2</a>', $foo); } return $foo; } ?>