Maison  >  Article  >  php教程  >  用php正则判断url地址并自动转换为超链接

用php正则判断url地址并自动转换为超链接

WBOY
WBOYoriginal
2016-06-06 20:00:521123parcourir

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@:%_/+.~#?/

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@:%_/+.~#?&//=]+)', '/1/2', $foo);

}

return $foo; 

}

 

echo autolink("http://www.baidu.com 百度 http://www.sina.com.cn 新浪");

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn