我们有一个像这样的字符串:
$string="Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
所以我想检查该字符串中是否有可用的单词。例如的话:
$words=['Ipsum','54'];
并且您可以看到Ipsum
在字符串中但54
不在字符串中,因此该函数应该回调true
(因为Ipsum
找到了)。我正在使用 php,感谢您的帮助。
php > $string="Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
php > $lookfor = "simply";
php > echo strpos($string, $lookfor) > 0 ? true : false ;
1
php > $lookfor = "simplest";
php > echo strpos($string, $lookfor) > 0 ? true : false ;
//nothing will be printed -))
只需从上面的代码片段中创建一个函数。
更新
$ cat search.php
<?php
$domain="asdasd asd fasdfasfafafad f454 asdfa";
$lookfor=array('as','f454');
function containsOneOfThoseWords($str, $words) {
foreach ($words as $word) {
if (strpos($str, $word) !== false) return true;
}
return false;
}
echo containsOneOfThoseWords($domain, $lookfor);
?>
$ php search.php; echo
1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句