Email+URL的判断和自动转换函数_PHP教程
程序员文章站
2022-04-25 14:39:15
...
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;
}
?>
{ 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;
}
?>
推荐阅读
-
判断、添加和删除WordPress置顶文章的相关PHP函数小结
-
PHP学习笔记之字符串编码的转换和判断
-
使用php判断浏览器的类型和语言的函数代码
-
php简单对象与数组的转换函数代码(php多层数组和对象的转换)
-
Email+URL的判断和自动转换函数
-
字符串长度函数strlen和mb_strlen的区别示例介绍,strlenmb_strlen_PHP教程
-
解析如何通过PHP函数获取当前运行的环境 来进行判断执行逻辑(小技巧)_PHP教程
-
PHP函数篇详解十进制、二进制、八进制和十六进制转换函数说明_PHP教程
-
PHP 将逗号、空格、回车分隔的字符串转换为数组的函数_PHP教程
-
解析php addslashes()与add*es()函数的区别和比较_PHP教程