<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>PHPDeveloper.org</title>
    <link>http://www.phpdeveloper.org</link>
    <description>Up-to-the Minute PHP News, views and community</description>
    <language>en-us</language>
    <pubDate>Sun, 19 May 2013 06:35:01 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[PHPro.org: Read Line From File (stream_get_line)]]></title>
      <guid>http://www.phpdeveloper.org/news/12392</guid>
      <link>http://www.phpdeveloper.org/news/12392</link>
      <description><![CDATA[<p>
The PHPro.org website has <a href="http://www.phpro.org/examples/Read-Line-From-File.html">a quick new tutorial</a> about a method (using streams) to get the information from a certain line of a file.
</p>
<blockquote>
Reading files in PHP can be a tricky business if not handled correctly. Most often when confronted with reading a line from, the nearest tool to hand is the file() function. The problem with using the file() function is that it reads the whole file into an array, and thus, into memory [...] A better, and more efficient way is to loop through the file stream using the stream_get_line() function. Care still needs to be taken to clear the buffer on each iteration, or the same problem could potentially arise as with the file() method. 
</blockquote>
<p>
The code calls <a href="http://php.net/fopen">fopen</a> on the file and, while it's not the end of the file, uses the <a href="http://php.net/stream_get_line">stream_get_line</a> function to grab things a line at a time. This saves you from having to read in the entire file (like with a <a href="http://php.net/file_get_contents">file_get_contents</a> or <a href="http://php.net/file">file</a> - especially good for large files.
</p>]]></description>
      <pubDate>Thu, 23 Apr 2009 09:36:51 -0500</pubDate>
    </item>
  </channel>
</rss>
