Forum Moderators: coopster

Message Too Old, No Replies

fopen? Right choice for local file?

         

Knowles

12:02 am on Aug 28, 2003 (gmt 0)

10+ Year Member



I am trying to open a local file, then starting from the 3rd line take every 3rd line. I know this has to go into a loop but I cant quite figure out how to make it work for some reason.

$myField = fgetcsv($myfile, 1024);
for ($x = 3; $x < count($myField); $x++) {
print($myField[0]);
}

If I run it just like this... its starts around line 252, then goes to like 488. If I add the x to $myField I get:

PHP Notice: Use of undefined constant x - assumed 'x' in list.php on line 19
PHP Notice: Undefined index: x in list.php on line 19

I am not sure where I need to head with this. I am sure I am not looking at the big picture here. I have written a million loops but I cant get this one down for some reason.

Fischerlaender

11:18 am on Aug 28, 2003 (gmt 0)

10+ Year Member



I think this should work:

$myField = file("filename.txt");
for ($x = 3; $x < count($myField); $x += 3) {
print $myField[$x];
}

justageek

11:22 am on Aug 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I haven't used fgetcsv but I think it is trying to return the fields as an array and you want the lines as an array so use file() to open the file as Fischerlaender said.