PHP - 检查一个字符串是否包含另一个字符串中的任何字符 [英] PHP - Check if a string contains any of the chars in another string

查看:44
本文介绍了PHP - 检查一个字符串是否包含另一个字符串中的任何字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 PHP 检查一个字符串是否包含另一个字符串中的任何字符?

How can I check if a string contains any of the chars in another string with PHP?

$a = "asd";
$b = "ds";
if (if_first_string_contains_any_of_the_chars_in_second_string($a, $b)) {
    echo "Yep!";
}

所以在这种情况下,它应该回显,因为 ASD 包含 D 和 S.

So in this case, it should echo, since ASD contains both a D and an S.

我想不使用正则表达式.

推荐答案

您可以使用

$a = "asd";
$b = "ds";
if (strpbrk($a, $b) !== FALSE)
    echo 'Found it';
else
    echo "nope!";

欲了解更多信息,请查看:http://php.net/manual/en/function.strpbrk.php

For more info check : http://php.net/manual/en/function.strpbrk.php

第二个参数区分大小写.

这篇关于PHP - 检查一个字符串是否包含另一个字符串中的任何字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆