SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,053
    Mentioned
    66 Post(s)
    Tagged
    0 Thread(s)

    PHP Function of the Day (2011-9-19): file_get_contents

    I'm skipping weekends with this btw...

    file_get_contents is the cleanest way to fetch a file in php. The offset and maxlength parameters will normally not see use unless the file is large enough to exhaust PHP's memory allowance.

    Code php:
    $file = file_get_contents($path);

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    Only thing I have to say here is to note the return type on this function - is String, not a file pointer, and altering the output does not change the file (though you could use file_put_contents to do so; it's slightly wasteful, as it will open/close the file twice.)

  3. #3
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,053
    Mentioned
    66 Post(s)
    Tagged
    0 Thread(s)
    Good to note that. Yeah, this function and it's cousin are for "quick and dirty" file manipulations. More intensive operations are better handled with the older commands or a file iterator.


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
  •