如何识别字符串是否包含a-z或a-z?或包含0-9?我需要一个函数来判断字符串属于字母表类型还是数字类型。非常感谢!!
您可以在PHP 上使用ctype
函数
CCD_ 2和CCD_。
用法:
//For alphabets
if(ctype_alpha('helloworld'))
{
echo "Yeah this is text";
}
//For digits...
if(ctype_digit('45'))
{
echo "Yeah this is a number";
}
您可以使用正则表达式来实现这一点:
$string = "abasdfBSDFSDFJKJH23409283049";
if (preg_match("^/[A-Za-z0-9]$/", $string))
{
//it matches
}