php自定义过滤字符函数
php自定义过滤字符函数:
/** * 保留指定类型的字符 * @param $content => * @param $type => 1整数,2小数,3字母,4汉字,5小数+字母+下划线,6数字+字母+汉字 * @return string **/ function glstr($content,$type=1){ if(strlen($content)<1) return $content; switch($type){ case 1: $content = preg_replace("/[^0-9]/u","",$content); break; case 2: $content = preg_replace("/[^0-9\.]/u","",$content); break; case 3: $content = preg_replace("/[^a-zA-Z_]/u","",$content); break; case 4: $content = preg_replace("/[^_\x{4e00}-\x{9fa5}]/u","",$content); break; case 5: $content = preg_replace("/[^0-9\.a-zA-Z_]/u","",$content); break; case 6: $content = preg_replace("/[^0-9\.a-zA-Z_\x{4e00}-\x{9fa5}]/u","",$content); break; case 7: $content = preg_replace("/[^0-9\.a-zA-Z_\x{4e00}-\x{9fa5}\@\#\%\+\-\.\,\/]/u","",$content); break; } return $content; }