after the search, The script riches the folder and read each individual file
and if it found h1 it will put each word of it in the array $h1words
the problem is, i want to compare the two arrays $words
and $h1words
and if there is one similar character, then it will show the 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);
}
}
}
Loop through the first array and compare each value to each value of the second array:
$i = 0
foreach($words as $array1){
foreach($h1words as $array2){
if($array1 === $array2){
//equal
}else{
//not equal
}
}
$i++
}
This will loop through each value in $words
and compare it to each value in $h1words
.
now It worked with preg_match(), thnx for your help
foreach($words as $wd){
foreach($h1words as $wh){
$findd=$wd;
$text=$wh;
if (preg_match("/".$findd."/i",$text)){
echo $str;
}else{continue;}