PHP code example of bcremer / line-reader

1. Go to this page and download the library: Download bcremer/line-reader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bcremer / line-reader example snippets


foreach (LineReader::readLines('some/file.txt') as $line) {
    echo $line . "\n"
}

$lineGenerator = LineReader::readLines('some/file.txt');
$lineGenerator = new \LimitIterator($lineGenerator, 2, 5);
foreach ($lineGenerator as $line) {
    echo $line . "\n"
}

foreach (LineReader::readLinesBackwards('some/file.txt') as $line) {
    echo $line;
}

$lineGenerator = LineReader::readLinesBackwards('some/file.txt');
$lineGenerator = new \LimitIterator($lineGenerator, 0, 5);

$lines = array_reverse(iterator_to_array($lineGenerator));
foreach ($line as $line) {
    echo $line;
}