SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2005
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Limit file_get_contents()?

    Is there a way I can limit file_get_contents, or a similar function? I only need about the first 1.25 KB or the first 35 lines to get what I need, but file get contents loads the whole file which i believe is slowing down my loop.

    Suggestions?

    Thanks,
    e39m5

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You can use fread() and limit it.

  3. #3
    SitePoint Zealot the DtTvB's Avatar
    Join Date
    Jul 2006
    Location
    Thailand
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to read the first 35 lines, it's very easy.
    Try learning by this example...
    PHP Code:
    <?php

    header 
    ('Content-Type: text/plain');

    // Create a file pointer and open a file for reading.
    $fp fopen('/etc/httpd/conf/httpd.conf''r');

    // Create some variables to recieve the data  and count the number of lines
    // read. Loop until the end of the file or the limit is reached.
    $limit 35;
    $data  '';
    $cline 0;
    while (!
    feof($fp) && ++$cline <= $limit) {
        
    $data .= fgets($fp);
    }

    // The data is stored in $data,   and we don't need to use the file pointer
    // anymore, so, now we can close the file. Bye-bye!
    fclose ($fp);

    // Echo the data.
    echo $data;

    ?>


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
  •