[英]How do I check if items in a array are present in a string php
我有一个项目数组,如何扫描字符串并检测该数组中的项目是否存在于字符串中的任何位置。 我看过其他与该问题类似的帖子,但都没有奏效。 也许是因为我正在使用wordpress
$string = get_the_title();// "The Man Who Wants You – Amos Lee [Vevo Official Video]" ---the string
$bads = get_the_tags();// array('Amos Lee', 'Foo Fighters', 'U2'); array of items
foreach($bads as $bad) {
$place = strpos($string, $bad);
if (!empty($place)) {
echo "True";
exit;
} else {
echo "Not True";
}
}
试试这个,检查strpos
是否不返回false:
foreach($bads as $bad) {
if (strpos($string, $bad) !== FALSE) {
echo "True";
exit;
} else {
echo "Not True";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.