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

From: Date: Mon, 12 May 2003 11:15:38 +0000
Subject: how to use strstr() (or similar) on an array?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-147289@lists.php.net to get a copy of this message
hello! i'm using the following script to scan each line of a text file for search term $src_trm. only lines that contain the requested expression are printed. $handle = fopen ($filename, "r"); $i = 1; while ($i <= $total_lines_of_file) { $buffer = fgets($handle, 4096); $buffer_raw = strip_tags($buffer); if(strstr($buffer_raw, $src_trm)) { $buffer = preg_replace("/$src_trm/", "<b>$src_trm</b>", $buffer); echo $buffer; } $i++; } fclose ($handle); there are two problems: 1. a user enters more than one word to search for: 'one two' is only found as exact match and not if a line containes 'two' somewhere at the beginning and 'one' somewhere at the end. maybe i should explode($src_trm) but then i don't know how to scan the file for lines that contain all requested expressions. 2. $buffer = preg_replace("/$src_trm/", "<b>$src_trm</b>", $buffer); this marks found words bold. unfortunately sometimes a word is also found inside a html tag. is there a possibility to exclude tags from this operation? thanks a lot for your effort! philipp rieger http://www.ipdraw.org/ ps: thanks to don read and jim lucas for their helpful answers to "[PHP] including() only given amount of lines"!

« previous php.general (#147289) next »