Home  >  Article  >  Backend Development  >  Email+URL judgment and automatic conversion function_PHP tutorial

Email+URL judgment and automatic conversion function_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:04:411043browse

function validateEmail($email)  
{     return eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $email);  
}  

function validateURL($url)  
{     return eregi("^((ht|f)tp://)((([a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3}))|(([0-9]{1,3}.){3}([0-9]{1,3})))((/|?)[a-z0-9~#%&'_+=:?.-]*)*)$", $url);  
}  

function convertURLS($text)  
{     $text = eregi_replace("((ht|f)tp://www.|www.)([a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})((/|?)[a-z0-9~#%&\/'_+=:?.-]*)*)", "http://www.\3", $text);  
    $text = eregi_replace("((ht|f)tp://)((([a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3}))|(([0-9]{1,3}.){3}([0-9]{1,3})))((/|?)[a-z0-9~#%&'_+=:?.-]*)*)", "\0", $text);  
    return $text;  
}  

function convertMail($text)  
{     $text = eregi_replace("([_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3}))", "\0", $text);  
    return $text;  
}  

function convertAllLinks($text)  
{     $text = convertURLS($text);  
    $text = convertMail($text);  
    return $text;  
}
?>  

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/315921.htmlTechArticle?php function validateEmail($email) {return eregi(^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$, $email); } function validateURL($url) {return eregi(^((ht|f)...
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