php判断是数字或英文或中文方法

作者:Liaodeity - 2015年05月29日

    通过正值表达式匹配,判断字符串中是否含有中文、英文、数字。

    在有时候,我们要判断一个字符串中包含什么的类型数据,从而判断这些数据是否为我们的正确的格式。

function checkStr($str){ 
    $output=''; 
    $a=ereg('['.chr(0xa1).'-'.chr(0xff).']', $str); 
    $b=ereg('[0-9]', $str); 
    $c=ereg('[a-zA-Z]', $str); 
    if($a && $b && $c){ $output='汉字数字英文的混合字符串';} 
    elseif($a && $b && !$c){ $output='汉字数字的混合字符串';} 
    elseif($a && !$b && $c){ $output='汉字英文的混合字符串';} 
    elseif(!$a && $b && $c){ $output='数字英文的混合字符串';} 
    elseif($a && !$b && !$c){ $output='纯汉字';} 
    elseif(!$a && $b && !$c){ $output='纯数字';} 
    elseif(!$a && !$b && $c){ $output='纯英文';} 
    return $output; 
}


本文作者: Liaodeity

本文链接: https://www.jianbaizhan.com/article/218.html

版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!


 请勿发布不友善或者负能量的内容。审查将对发布广告等违规信息进行处罚!