Home >Backend Development >PHP Tutorial >A modified function that automatically converts URLs and emails, powerful_PHP tutorial

A modified function that automatically converts URLs and emails, powerful_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:24:18809browse

It can convert
starting with http and ftp, as well as mail
and
starting with www, which is very good

function enable_urls($str){
$str = ereg_replace("(www.[a-zA-Z0-9@:%_.~#-?&]+)", " 1", $str);// Automatically convert links starting with www
$ str = ereg_replace("(((f|ht){1}tp://)[a-zA-Z0-9@:%_.~#-?&]+)", "1", $str) ;//Convert links starting with http:// and ftp://
$str=str_replace(LINKttp://,http://,$str);
$str = ereg_replace("([ _.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})","1", $str); //Convert email address
return $str;
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532157.htmlTechArticleYou can convert those starting with http and ftp, as well as mail and www. Function enable_urls( $str){ $str = ereg_replace("(www.[a-zA-Z0-9@:%_.~#-?// Automatically convert the chain starting with www...
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
Previous article:What is PHP_PHP TutorialNext article:What is PHP_PHP Tutorial