RE: [PHP] Files question

From: Ray Hunter (bigdog_at_venticon.com)
Date: 10/30/03


To: php-general@lists.php.net
Date: Thu, 30 Oct 2003 07:56:48 -0700


> Well, Bas, the fopen and it's associated manual pages describe just how
> to do this. Basic example
>
> $theFile = fopen("myfile.foo", "r"); //open the file for reading
> while(!feof($theFile)){ // while the file is not at the end of the file
> $theLine = fgets($theFile, 1024); // get a line, specify a
> length
> echo $theLine; // print out the line you just got
> } //close the while loop

http://us2.php.net/manual/en/function.file.php

Using file will read each line of a file into an element of the returned
array. then you can loop through the array and pull out line by
line...example:

$lines = file( "somefile.txt" );

foreach( $lines as $line => $value ) {
  echo "$line = $value<br>";
}

HTH

--
Ray


Relevant Pages

  • Re: Import from finance.yahoo.com
    ... containing tables of stock statistics, it runs down the page and pulls the ... You could do the same thing using the 'find' command and I guess not have to ... Using the find command might also allow you to pull in the whole page (using ... an array and then looping through the array. ...
    (microsoft.public.excel.programming)
  • Re: drive failure during rebuild causes page fault
    ... Pull a drive and rebuild onto hot spare. ... but not page fault when it's not / ... what's the story with the new array appearing when you ...
    (freebsd-stable)
  • Re: Array and resize
    ... > Thanks for the reply Bob, ... > Excel worksheet. ... >> You are not creating a 2D array, but an array containing arrays, and you ... >> HTH ...
    (microsoft.public.excel.programming)
  • Re: Does MySql have any built in search functionality
    ... >> mainContent ORDER BY number of matches per entry DESC ... > HTH ... available you could read the query result into an array and then use PHP ...
    (comp.lang.php)
  • Re: Cant reverse array of Integers ?
    ... as I'm running out of hair to pull out :-( ... The PixLine will typically contain a single value of 255 at a random ... glaringly obvious to a knowledgable delphi wizard:P The array is ...
    (alt.comp.lang.borland-delphi)