php 项目常用函数
2014-12-23 22:56
411 查看
1.清空文章中的链接
function clear_link($content) {
return preg_replace_callback("/<a[^>]*>(.*?)<\/a>/is", "_clear_link", $content);
}
调用回调函数_clear_link
function _clear_link($matchs) {
if(strpos($matchs[0], “www”) !== false) return $matchs[0]; //排除指定的链接 如www
return $matchs[1];
}
2.图片判断
function is_image($file) {
return preg_match("/^(jpg|jpeg|gif|png|bmp)$/i", file_ext($file)); //file_ext获取文件扩展名
}
3.网址判断
function is_url($url) {
return preg_match("/^[http|https]\:\/\/[a-z0-9\/\.\#\&\?\;\,]{4,}$/", $url);
}
4.邮箱判断
function is_email($email) {
return strlen($email) > 6 && preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $email);
}
5.电话判断
function is_telephone($telephone) {
return preg_match("/^[0-9\-\+]{7,}$/", $telephone);
}
6.qq判断
function is_qq($qq) {
return preg_match("/^[1-9]{1}[0-9]{4,12}$/", $qq);
}
function clear_link($content) {
return preg_replace_callback("/<a[^>]*>(.*?)<\/a>/is", "_clear_link", $content);
}
调用回调函数_clear_link
function _clear_link($matchs) {
if(strpos($matchs[0], “www”) !== false) return $matchs[0]; //排除指定的链接 如www
return $matchs[1];
}
2.图片判断
function is_image($file) {
return preg_match("/^(jpg|jpeg|gif|png|bmp)$/i", file_ext($file)); //file_ext获取文件扩展名
}
3.网址判断
function is_url($url) {
return preg_match("/^[http|https]\:\/\/[a-z0-9\/\.\#\&\?\;\,]{4,}$/", $url);
}
4.邮箱判断
function is_email($email) {
return strlen($email) > 6 && preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $email);
}
5.电话判断
function is_telephone($telephone) {
return preg_match("/^[0-9\-\+]{7,}$/", $telephone);
}
6.qq判断
function is_qq($qq) {
return preg_match("/^[1-9]{1}[0-9]{4,12}$/", $qq);
}