Results 1 to 2 of 2

Thread: Reading a File Line by Line

  1. #1
    Join Date
    Apr 2005
    Posts
    46,704

    Default Reading a File Line by Line

    <?php
    $file = fopen("flename.txt", "r") or exit("Unable to open file!");
    while(!feof($file))
    {
    echo fgets($file). "<br>";
    }
    fclose($file);
    ?>

  2. #2
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Or you can do

    Code:
    <?php
    
    $file_all_lines = file("filename.txt");
    
    foreach ($file_all_lines as $line)
    {
        echo $line . "<br />";
    }
    It is better practice not to end php code with ?> unless it is required. For example, you need some HTML code after it.

    Use [/code] BB code for code. It is same as quote. Replace QUOTE with CODE (or code)
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •