1. Go to this page and download the library: Download fruivita/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/ */
fruivita / line-reader example snippets
use FruiVita\LineReader\Facades\LineReader;
$generator = LineReader::readLines($file_path);
// or
$length_aware_paginator = LineReader::readPaginatedLines($file_path, $per_page, $page);
use FruiVita\LineReader\Facades\LineReader;
public function example()
{
foreach (LineReader::readLines($file_path) as $key => $line)
{
// $key is 0 when reading the 1st line, 1 when reading the 2nd line, and so on.
// $line is a string with the contents of the line.
}
}
use FruiVita\LineReader\Facades\LineReader;
/**
* @param string $file_path full path of the file to be read
*
* @throws \FruiVita\LineReader\Exceptions\FileNotReadableException
*
* @return \Generator
*/
LineReader::readLines(string $file_path);
use FruiVita\LineReader\Facades\LineReader;
public function example()
{
$per_page = 15;
$page = 2;
$length_aware_paginator = LineReader::readPaginatedLines(string $file_path, int $per_page, int $page);
// The index of the items in the collection respects their position in the file using a zero-based index,
// that is, in the example above the 1st item on page 2 will have index 15, since it is the 16th line of
// the file and the last item on page 2 will have index 29, since it is the 30th line of the file.
}
use FruiVita\LineReader\Facades\LineReader;
/**
* @param string $file_path full path of the file to be read
* @param int $per_page
* @param int $page
* @param string $page_name
*
* @throws \FruiVita\LineReader\Exceptions\FileNotReadableException
* @throws \InvalidArgumentException
*
* @return \Illuminate\Pagination\LengthAwarePaginator
*/
LineReader::readPaginatedLines(string $file_path, int $per_page, int $page, string $page_name = 'page');