Skip to content

Instantly share code, notes, and snippets.

@doulmi
Last active November 30, 2017 15:44
Show Gist options
  • Save doulmi/4ca556cfbad6207ce7d4927d7c1c2f89 to your computer and use it in GitHub Desktop.
Save doulmi/4ca556cfbad6207ce7d4927d7c1c2f89 to your computer and use it in GitHub Desktop.
Laraval way to read lines from a file
/**
* Read lines from the file, auto detecting line endings.
*
* @param string $filePath
*
* @return array
*/
protected function readLinesFromFile($filePath)
{
// Read file into an array of lines with auto-detected line endings
$autodetect = ini_get('auto_detect_line_endings');
ini_set('auto_detect_line_endings', '1');
$lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
ini_set('auto_detect_line_endings', $autodetect);
return $lines;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment