如何使用 Stristr 进行搜索


how to search with stristr

i 有 2 个数组

$filtered_url_list= array("www.salmat.", "www.webcentral.");

 $files = array("http://www.salmat.", "http://www.webcentral.", "http://abc.");

我想在数组 $files 中搜索 $filtered_url_list 的元素。如果 $files ' 元素字符串的一部分匹配,则需要echo相应的 $files' 字符串

我的代码看起来像这样

foreach($filtered_url_list as $check_val)
{
  $found=FALSE;
  foreach($files as $file_val)
  {
    if(stristr($check_val,$file_val)!==FALSE)
    {
        $found=TRUE;
    }
  }
  if(!$found)
  {
    echo $file_val,"'n";
  }

}例:
www.salmat. is present in http://www.salmat. if this is true then echo http://www.salmat.我的回声陈述不正确。但是我不明白如何使其正确

请建议

谢谢

echo放在foreach中。此外,stristr函数的参数顺序是错误的。

foreach($filtered_url_list as $check_val)
{
  $found=FALSE;
  foreach($files as $file_val)
  {
    if(stristr($file_val,$check_val)!==FALSE)
    {
      $found=TRUE;
      echo $file_val,"'n";
    }
  }
}

试试这段代码:-

foreach($filtered_url_list as $check_val)
{
  if(in_array ($check_val ,$contents))
  {
    //$chcekc_val values is present in $contents array. 
  }
 }

供参考 http://php.net/manual/en/function.in-array.php

改用strcmp

    if(strcmp($check_val,$file_val) ==0)