在 JS 中我使用了这段代码:
if(string.match(/[^A-Za-z0-9]+/))
但我不知道,如何在 PHP 中做到这一点。
最佳答案
使用 preg_match() .
if (!preg_match('/[^A-Za-z0-9]/', $string)) // '/[^a-z\d]/i' should also work.
{
// string contains only english letters & digits
}
关于php - 如何检查一个php字符串是否只包含英文字母和数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9351306/