On Wed, May 09, 2001 at 06:13:17PM -0700, Dexter wrote:
> Does the array parameter of ereg actually return strings matched? I
> tried to read a file looking for a string using ereg and wanted to put
> the matched strings found in an array. Doesn't seem to be happening
> with the following.
>
> $contents=fread($readfile,100000);
> $pattern="<a href.*\">";
> $i=0;
> while(!feof($readfile))
> {
> $contents=fgets($readfile,4065);
> if(eregi($pattern,$contents,$regs))
> {
> echo "$regs[$i]<br>";
> }
> $i++;
> }
Yes, it actually does return strings matched. I would not expect your
code, as you typed it, to do what you expect. I realigned things to make
it easier to see what is happening.
With what you have, it is very unlikely that you will ever print out a
match. You are incrementing your counter for every line of the file,
not for every match actually found. Try this code instead:
<?php
$contents=fread($readfile,100000);
$pattern="<a href.*\">";
while(!feof($readfile)) {
$contents=fgets($readfile,4065);
if(eregi($pattern,$contents,$regs)) {
for($i = 0; $i < sizeof($regs); $i++) {
echo "$regs[$i]<br>";
}
}
}
?>
--
Jason Stechschulte
[EMAIL PROTECTED]
--
I hope I'm not getting so famous that I can't think out load [sic] anymore.
-- Larry Wall in <[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]