On Jan 7, 6:01 pm, Michael <[email protected]> wrote:
>
> The issue is with this code, is while it reads the whole file, the array out
> put of preg_match_all is empty. (note that preg_match also returns empty).
>
> $fh = fopen($filename,"r");
> while ($content = fgets($fh)) {
>
> preg_match_all($pattern,$content,$matches);
>
> }
>
> fclose($fh);
>
> print_r($matches);


Unless I'm reading your code all wrong like, at the termination of the
the while loop $matches will hold the result of the preg match on the
last line of the file.  So, unless you've got matching text in the
last line of the file, it'll be empty -- as per the output.

You need to merge the results after every call to preg_match_all() a
la

     // add it to our array:
     foreach($matches[0] as $m) $results[] = $m;

I'm experiencing an unfashionable amount of anticipation for hearing
tomorrow what performance problems will be introduced by adding this
extra component into the loop for 50,000 iterations.

-s

--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]
-~----------~----~----~----~------~----~------~--~---

Reply via email to