Home  >  Article  >  php教程  >  php 给url添加超级链接方法

php 给url添加超级链接方法

WBOY
WBOYOriginal
2016-06-02 09:14:591606browse
如在我们提供网地址是 httt://www.zhutiai.com 但我们使用下面程序可以自动给它加个超级连接哦。
提供看一个php高级的做法

如在我们提供网地址是 httt://www.phprm.com 但我们使用下面程序可以自动给它加个超级连接哦。
提供看一个php教程高级的做法

function autolink($foo) 
{
$foo = eregi_replace('(((f|ht){1}tp://)[-a-za-z0-9@:%_+.~#?&//=]+)', '1', $foo);
if( strpos($foo, "http") === false ){
$foo = eregi_replace('(www.[-a-za-z0-9@:%_+.~#?&//=]+)', '1', $foo);
}else{
$foo = eregi_replace('([[:space:]()[{}])(www.[-a-za-z0-9@:%_+.~#?&//=]+)', '12', $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('$1', '$1', '$1'); 
$text = preg_replace($search, $replace, $text); 
return $text; 
}

永久链接:

转载随意!带上文章地址吧。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn