function autolink($foo)
{
$foo = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_/+.~#?&//=]+)', '<a 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" target="_blank" rel="nofollow" >/1</a>', $foo);
}else{
$foo = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_/+.~#?&//=]+)', '/1<a href="http:///2" target="_blank" rel="nofollow" >/2</a>', $foo);
}
return $foo;
}
echo autolink("http://www.baidu.com 百度 http://www.sina.com.cn 新浪");
本文介绍了一种PHP函数autolink,用于自动将文本中的URL链接替换为带有目标和rel属性的HTML锚标签,实现了对网页内容的美化与链接标准化。
1003

被折叠的 条评论
为什么被折叠?



