1. Go to this page and download the library: Download nekman/files 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/ */
nekman / files example snippets
use function Nekman\Files\file_read_lines;
use function Nekman\Files\file_write_lines;
# Reading a file
$it = file_read_lines("/path/to/my/file");
foreach ($it as $line) {
// This is ready, line-by-line. The file is never read completely into memory at once.
echo $line;
}
# Writing a file
file_write_lines("/path/to/my/file", ["line1", "line2"]);
# Writing a file using Generator
function my_generator(): iterable
{
yield "line1";
yield "line2";
}
file_write_lines("/path/to/my/file", my_generator());
use function Nekman\Files\file_read_csv;
use function Nekman\Files\file_write_csv;
# Reading from a CSV
$it = file_read_csv("/path/to/csv");
foreach ($it as $row) {
[$column1, $column2] = $row;
echo "$column1,$column2";
}
# Writing a CSV file
file_write_csv("/path/to/csv", [["column1x", "column2x"], ["column1y", "column2y"]]);
# Writing a file using Generator
function my_generator(): iterable
{
yield ["column1x", "column2x"];
yield ["column1y", "column2y"];
}
file_write_csv("/path/to/my/file", my_generator());
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.