php-general | 2001122
Date: 12/30/01
- Next message: Carlos Fernando Scheidecker Antunes: "[PHP] How to convert integers representations of a date to a date format variable"
- Previous message: GoodFella: "Re: [PHP] MySQL problem"
- In reply to: John Weez: "[PHP] Parsing out numbers from a string"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
* John Weez (john <email protected>) [Dec 30. 2001 03:23]:
> I have a small program which captures the output of a webpage and puts the
> data in to a string variable.
> I then use teh strip tags function of php to clean it up a bit.
> then i want to use regular expressions to extract all the numbers from the
> page ..they are like this usually numbers.numbers (IE: 40.40 ).
> For some reason my expressions are not matching anything in the string
> unless i type exactly what i am looking for... could the fact that there
> are line reurns in the string be causing a problem? or do i need to
> somehow tell php to goto the next line?
How are you grabbing all the data from the page?
> I had an older version of the program which saved teh data to a file and
> then PhP scanned the file line by line..this worked...but i'm trying to
> make a more elegant solution that won;t kill my hard drive faster ;)
It's going to use a bit of memory to search an entire page with a
regular expression. It's probably going to be slow(er) no matter how you
slice it.
I would use the PCRE functions; preg_match_all() probably..
Look over these:
<http://www.php.net/manual/en/pcre.pattern.modifiers.php>
I think you'll want to use m (and g is default, as the comment says).
Something like this may work:
<?php
/* untested */
preg_match_all('/([0-9]+\.[0-9]+)/m',$string,$matches);
while(list(,$match) = each($matches[0]))
{
print "$match\n";
}
?>
-- Brian Clark | Avoiding the general public since 1805! Fingerprint: 07CE FA37 8DF6 A109 8119 076B B5A2 E5FB E4D0 C7C8 Recursive: Adj. See Recursive.-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe <email protected> For additional commands, e-mail: php-general-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Carlos Fernando Scheidecker Antunes: "[PHP] How to convert integers representations of a date to a date format variable"
- Previous message: GoodFella: "Re: [PHP] MySQL problem"
- In reply to: John Weez: "[PHP] Parsing out numbers from a string"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

