Skip to content

Instantly share code, notes, and snippets.

@ojhaujjwal
Last active April 6, 2020 01:31
Show Gist options
  • Save ojhaujjwal/181ca91b48b571db9a69aeebc7fea75f to your computer and use it in GitHub Desktop.
Save ojhaujjwal/181ca91b48b571db9a69aeebc7fea75f to your computer and use it in GitHub Desktop.
<?php
function getLines($file): Generator {
$f = fopen($file, 'r');
if (!$f) throw new Exception();
while ($line = fgets($f)) {
yield $line;
}
fclose($f);
}
$filePath = $argv[1];
$lines = getLines($filePath);
foreach ($lines as $line) {
echo $line. "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment