php - 检查字符串是否在php中包含字母

标签 php regex string preg-replace preg-match

如何在 PHP 中检查字符串是否有字母

ctype_alphactype_digit没有帮助。他们有什么方法吗?

最佳答案

您可以为此使用 preg_match

if(preg_match("/[a-z]/i", $string)){
    print "it has alphabet!";
}

如果要检查所有字符是否为字母,请在正则表达式周围使用 anchor 。例如 ^[a-z]+$.

关于php - 检查字符串是否在php中包含字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22458156/

相关文章:

php - foreach() 跳过数组中的第一个元素

swift - 正则表达式应用到字符串?

python - 替换字符串中的特定单词 (Python)

php - Laravel - PDO - 动态表名

php - 更改循环中的最后一项输出 (ACF)

php - 使用preg_match替换字符串

PHP trim/rtrim/ltrim VS 正则表达式

java - 从字符串中提取数字和名称

java - 将文件数据读入两个数组(不是数组列表)

java - 分割字符串点分隔