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:[EMAIL PROTECTED]]
Sent: Monday, March 12, 2001 3:36 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] search a text file


[quotes returned to bottom-posting, for clarity]

In article 
<[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Peter Benoit) wrote:

> In article 
> <[EMAIL PROTECTED]>,
>  [EMAIL PROTECTED] (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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to