Multiple search word matching using strpos

前端 未结 1 866
自闭症患者
自闭症患者 2021-01-24 10:12

I wonder if anyone can help with a little problem I can\'t seem to fix - my head is going round in circles at the moment...

Ok I have a .txt file with numerous lines of

相关标签:
1条回答
  • 2021-01-24 10:47

    Here's my code:

    $searchTerms = explode(' ', $search);
    $searchCount = count($searchTerms);
    foreach($lines as $line)
     {
        if ($counter <= 4) {
            $matchCount = 0;
            foreach ($searchTerms as $searchWord) {
                if (strpos($line, $searchWord) !== false ) {
                    $matchCount +=1;
                } else {
                    //break out of foreach as no need to check the rest of the words if one wasn't found
                    continue; 
                }
            }
            if ($matchCount == $searchCount) {
                $found = true;
                $line = '<img src=""> <a href="">'.$line.'</a><br>';
                echo $line;
                $counter = $counter + 1;
            }
    
        }
    }
    
    0 讨论(0)
提交回复
热议问题