Skip to content

Instantly share code, notes, and snippets.

@blar
Created September 24, 2012 20:08
Show Gist options
  • Select an option

  • Save blar/3778056 to your computer and use it in GitHub Desktop.

Select an option

Save blar/3778056 to your computer and use it in GitHub Desktop.
<?php
function LineIterator($file) {
$handle = fopen($file, 'r');
return function() use($handle) {
if(!feof($handle)) {
return fgets($handle);
}
fclose($handle);
};
}
$iterator = LineIterator('/etc/hosts');
while($line = $iterator()) {
echo $line;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment