RE: [PHP] search a text file

From: Date: Mon, 12 Mar 2001 20:41:23 +0000
Subject: RE: [PHP] search a text file
Groups: php.general 
Request: Send a blank email to php-general+get-43542@lists.php.net to get a copy of this message
Very good info, but this text is located in a text file. How can I reference it this way? -----Original Message----- From: CC Zona [mailto:cczona@nospam.invalid] Sent: Monday, March 12, 2001 3:36 PM To: php-general@lists.php.net Subject: Re: [PHP] search a text file [quotes returned to bottom-posting, for clarity] In article <309828428FB7D411A53C00508BB18D261CC6E1@triton.triton-network.com>, pbenoit@triton-network.com (Peter Benoit) wrote: > In article > <309828428FB7D411A53C00508BB18D261CC6DA@triton.triton-network.com>, > pbenoit@triton-network.com (Peter Benoit) wrote: > > > I've got a bit of a task where I need to poll a text file for several > lines > > of text which is buried deep within the file. These lines change each > day, > > but the text surrounding them do not. > > > > Is it possible to extract these lines of information based on the text > > surrounding them? > > Sure. preg_match() would be one way. > OK, I'm a little new to this, else I would have known that. Any examples > out there I could use/modify? Probably. You could check the manual's page on preg_match (the user annotations often have very useful code examples), phpbuilder.com, hotscripts.com, etc. A quick, oversimplified example: Let's say your complete text was (no laughing now <g>) "Mary had a little lamb, its fleece was white as snow." where "Mary had a " and "fleece was white as snow." are always consistent but whatever's happens to be the portion of the text between them is what you want to extract. You could do something like-- $search_string="Mary had a little lamb, its fleece was white as snow."; $status=preg_match("/^Mary had a(.*)(?=fleece was white as snow.)$/i",$search_string,$match_text); In which case, $status would evaluate to true if a (case-insensitive) match was found, and $match_text[1] would contain " little lamb, its ". -- CC -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#43542) next »