php 给url添加超级链接方法
如在我们提供网地址是 httt://www.zhutiai.com 但我们使用下面程序可以自动给它加个超级连接哦。
提供看一个php高级的做法
提供看一个php高级的做法
如在我们提供网地址是 httt://www.phprm.com 但我们使用下面程序可以自动给它加个超级连接哦。
提供看一个php教程高级的做法
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; } $str = 'http://'; echo autolink($str);
更多详细内容请查看:http://www.phprm.com/wy/js-ajax/33810.htm
下面介绍一个简单的做法
function showtext($text){ $search = array('|(http://[^ ]+)|', '|(https教程://[^ ]+)|', '|(www.[^ ]+)|'); $replace = array('<a href="$1" target="_blank">$1</a>', '<a href="$1" target="_blank">$1</a>', '<a href="http://$1" target="_blank">$1</a>'); $text = preg_replace($search, $replace, $text); return $text; }
永久链接:http://www.phprm.com/develop/39773.html
转载随意!带上文章地址吧。