gpt4 book ai didi

php - 如何检查一个php字符串是否只包含英文字母和数字?

转载 作者:IT王子 更新时间:2023-10-29 00:43:00 26 4
gpt4 key购买 nike

在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com