/** * 检查字符串中是否有汉字/数字/英文字 * -- 返回结果解释: * 1 代表汉字 * 2 代表数字 * 3 代表英文 * 例:返回结果为 23 ,则代表包含数字和英文 * @param $str * @return string */ function checkStr($str) { $output=''; $a=preg_match('/['.chr(0xa1).'-'.chr(0xff).']/', $str); $b=preg_match('/[0-9]/', $str); $c=preg_match('/[a-zA-Z]/', $str); if($a && $b && $c) // $output='汉字数字英文的混合字符串'; $output = '123'; elseif($a && $b && !$c) // $output='汉字数字的混合字符串'; $output = '12'; elseif($a && !$b && $c) // $output='汉字英文的混合字符串'; $output = '13'; elseif(!$a && $b && $c) // $output='数字英文的混合字符串'; $output = '23'; elseif($a && !$b && !$c) // $output='纯汉字'; $output = '1'; elseif(!$a && $b && !$c) // $output='纯数字'; $output = '2'; elseif(!$a && !$b && $c) // $output='纯英文'; $output = '3'; return $output; }