Re: how to use strstr() (or similar) on an array?

From: Date: Mon, 12 May 2003 23:32:02 +0000
Subject: Re: how to use strstr() (or similar) on an array?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-147381@lists.php.net to get a copy of this message
This will solve the problem of only showing line with ALL search words in it, but I don't have the skills to figure out the bolding problem within tags, so i've left the strip_tags() line in there. Good luck. <? $src_trm = "one two"; $searchWords = explode(' ',$src_trm); $handle = fopen("searchee.txt", "r"); while(!feof($handle)) { $buffer = strip_tags(fgets($handle, 4096)); foreach($searchWords as $word) { $pos = strpos($buffer,$word); if($pos === false) { // not found } else { $wordFound++; $buffer = str_replace($word,"<b>{$word}</b>",$buffer); } } if($wordFound >= count($searchWords)) { echo $buffer."<br />"; } $wordFound = 0; } fclose($handle); ?> Justin on 13/05/03 12:42 AM, iliketheworld@gmx.ch (iliketheworld@gmx.ch) wrote: >> <? >> >> $src_trm = "one two"; >> $searchWords = explode(' ',$src_trm); >> >> $handle = fopen("searchMe.txt", "r"); >> while(!feof($handle)) >> { >> $buffer = fgets($handle, 4096); >> foreach($searchWords as $word) >> { >> $pos = strpos($buffer,$word); >> if($pos === false) >> { >> // not found >> } >> else >> { >> $wordFound = 1; >> } >> } >> if($wordFound) >> { >> echo $buffer."<br />"; >> } >> $wordFound = 0; >> } >> fclose($handle); >> >> ?>

« previous php.general (#147381) next »