Email+URL的判断和自动转换函数
Email+URL的判断和自动转换函数
发布时间:2016-12-29 来源:查字典编辑
摘要:

<?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)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~#%&'_+=:?.-]*)*)", "<a href=""></a>", $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}))", "<a href='mailto:'></a>", $text);

return $text;

}

function convertAllLinks($text)

{$text = convertURLS($text);

$text = convertMail($text);

return $text;

}

?>

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新php教程学习
热门php教程学习
编程开发子分类