#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    6
    Rep Power
    0
    hello!
    i need some help about this:
    i have tried to make a script that would read the first line in "stuff.txt" and print it on the web, does anyone know how i can do this?

    and one more thing.

    how about a whole file?
    and how can i parse like
    xermin.net. IN A 62.92.229.219
    to xermin.net -> 62.92.229.219 ?

    thanks

    ------------------
    -cryz-
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    24
    Rep Power
    0
    Getting the first line of a file is easy.
    $fd = fopen($file,"r");
    $firstline = fgets($fd, 4096);
    fclose($fp);

    if you want to read a whole file as you described, use something like the following:
    $fd = fopen($file,"r");
    while (!feof($fd))
    {
    $thisline = fgets($fd, 4096);
    $temp = explode(" in ", $thisline);
    ${temp[0]} = $temp[1];
    }
    fclose($fp);

    So for a file as you said you kave
    key in value
    if your not breaking it up be " in " replace the " in " with whatever you want.

    Hope this helps, if not mail me.
    Sparky@Spartanweb.co.uk

    Later
    Sparky
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Washington, USA
    Posts
    52
    Rep Power
    15
    You can also just throw the contents of the file in an array and reference the first item in the array like this:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?
    $file_contents = file("/path/to/file.txt");
    print($file_contents[0]);
    ?>
    [/code]

    Keep in mind that numbering for arrays begins at 0 (zero) so if you wanted to reference the 6th line in a text file you'd use $file_contents[5]



    ------------------
    <UL TYPE=SQUARE>
    <LI> TD Scripts
    <LI> Script School
    <LI>php-scripts
    </UL>

Similar Threads

  1. fopen() / fread() issue
    By rob_n in forum PHP Development
    Replies: 4
    Last Post: October 24th, 2003, 12:16 PM
  2. fopen / fread not reading the entire external file
    By swirling in forum PHP Development
    Replies: 5
    Last Post: September 11th, 2003, 12:55 PM
  3. fopen() && fread() speed
    By Jason Knight in forum PHP Development
    Replies: 2
    Last Post: July 2nd, 2003, 01:05 PM
  4. fread() or fopen() trouble
    By Chanyom in forum PHP Development
    Replies: 4
    Last Post: April 29th, 2003, 12:33 AM
  5. alternative to fopen, fread
    By tuxpow3r in forum PHP Development
    Replies: 3
    Last Post: January 22nd, 2002, 01:06 AM

IMN logo majestic logo threadwatch logo seochat tools logo