字符串包含数组中的任何项目(不区分大小写) [英] String contains any items in an array (case insensitive)
本文介绍了字符串包含数组中的任何项目(不区分大小写)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查 $string
是否包含数组中表示的任何项目?
How can i check if a $string
contains any of the items expressed in an array?
$string = 'My nAmE is Tom.';
$array = array("name","tom");
if(contains($string,$array))
{
// do something to say it contains
}
有什么想法吗?
推荐答案
这是您想要的吗?我希望代码正在编译:)
is that what you wanted? i hope that code is compiling :)
$string = 'My nAmE is Tom.';
$array = array("name","tom");
if(0 < count(array_intersect(array_map('strtolower', explode(' ', $string)), $array)))
{
//do sth
}
这篇关于字符串包含数组中的任何项目(不区分大小写)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文