标签: php如何检测字符串为纯英文

  • php如何检测字符串为纯英文_读书小站

    本文收集自网络,侵删!

    php如何检测字符串为纯英文

    PHP中使用preg_match()函数判断字符串是否为纯英文,具体方法如下:

    首先,新建一个php项目文件;

    php项目文件新建好后,在文件中定义一个字符串;

    $str1 = 'yisu';

    字符串定义好后,使用preg_match()函数判断字符串是否为纯英文;

    $str1 = 'yisu';

    $str2 = preg_match("/^[A-Za-z]+$/",$str);

    最后,判断结果后,使用echo函数输出结果即可;

    $str1 = 'yisu';

    $str2 = preg_match("/^[A-Za-z]+$/",$str);

    if($str2){

    echo '字符串为纯英文 ';

    }