Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 检查字符串数组中的字符串是否在字符串中可用_Php - Fatal编程技术网

Php 检查字符串数组中的字符串是否在字符串中可用

Php 检查字符串数组中的字符串是否在字符串中可用,php,Php,我知道php中的所有字符串函数(preg_match、strpos…)都允许我在字符串中查找字符串。我的目的是在如下字符串中查找字符串数组中的字符串: $pattern = array("jpg", "bmp"); $subject = $bild->dateiname; <pre> <?php $pattern = array("jpg", "bmp"); $yourString ="bmp dd ddd

我知道php中的所有字符串函数(preg_match、strpos…)都允许我在字符串中查找字符串。我的目的是在如下字符串中查找字符串数组中的字符串:

         $pattern = array("jpg", "bmp");
         $subject = $bild->dateiname;
<pre>
<?php       

  $pattern = array("jpg", "bmp");

  $yourString ="bmp dd ddd ddd";
  $string = (explode(" ",$yourString));


    echo findeStirng($pattern,$string);

    function findeStirng($pattern,$string){
         foreach ($string as $val){
             foreach ($pattern as $valpat){
             $find="";
             if ($val==$valpat){
                 $find ="finde string";
                 return $find;
                 break;
             }
             }
             }
         }
?>

</pre>

任何想法,如何使用php函数实现我的意图?

在数组中查找字符串


如果您只想查看主题字符串中是否有任何一个数组字符串,请尝试替换它们并检查是否有替换:

if(str_replace($pattern, '', $subject, $count) && $count) {
    echo 'something was found';
}
或:

要捕获匹配项,请使用
preg_match
或捕获所有匹配项:


然后检查
$matches

您看过手册了吗?答案就在那里。使用谷歌也一样。你需要知道找到了哪一个,或者是否找到了任何一个吗?。。。或者如果全部找到了?
if(preg_match('/\.('.intlode('.$patern.))/,$subject))回显“是”
if(str_replace($pattern, '', $subject, $count) && $count) {
    echo 'something was found';
}
preg_match_all('/(' . implode('|', $pattern) . ')/', $subject, $matches);