繁体   English   中英

我想将一个数组的值与另一个数组的值进行比较

[英]I want to compare values from one array with values of another array

搜索后,脚本将丰富文件夹并读取每个文件
如果找到h1,它将把每个单词放入数组$h1words
问题是,我想比较两个数组$words$h1words
如果有一个相似的字符,它将显示h1

if (isset($_GET["sub"]) && $_GET["sub"]=="Search"){

    // Open a known directory, and proceed to read its contents
    $dir="c1/cat1/";
    $words=explode(" ",$_GET["search"]);
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            while (($file = readdir($dh)) !== false) {
                if ($file=="" or $file=="." or $file==".." or $file=="index.php" or $file=="index.html") {
                    continue;
                }

                $filet=$dir.$file;
                if (is_readable($filet)){
                    $filee=fopen($filet,"r");
                    while(!feof($filee)){
                        $str=strip_tags(fgets($filee),"<h1>");
                        $findme="<h1>";
                        $pos = strpos($str, $findme);
                        if ($pos!==false){
                            $h1words=explode(" ",$str);
                        }else{}

                    }
            echo "<br /><hr /><br />";
            fclose($filee);
                }

            }
            closedir($dh);

        }
    }
}

循环遍历第一个数组,并将每个值与第二个数组的每个值进行比较:

$i = 0
foreach($words as $array1){
  foreach($h1words as $array2){
    if($array1 === $array2){
      //equal
    }else{
      //not equal
    }
  }
  $i++
}

这将遍历$words每个值,并将其与$h1words每个值进行比较。

现在它与preg_match(),thnx一起工作为您提供帮助

foreach($words as $wd){
    foreach($h1words as $wh){
    $findd=$wd;
    $text=$wh;
    if (preg_match("/".$findd."/i",$text)){
        echo $str;

    }else{continue;}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM