Download the PHP package michaelgarrez/text-file without Composer
On this page you can find all versions of the php package michaelgarrez/text-file. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download michaelgarrez/text-file
More information about michaelgarrez/text-file
Files in michaelgarrez/text-file
Informations about the package text-file
TextFile
Introduction
This library eases manipulation of text files in PHP by providing multiple methods to read / parse / write text files.
Installation
Basics
Opening a file
If text_file.txt file exists it will be opened otherwise it will be created.
Walking
WalkerInterface
All walking related operations are done by an instance of WalkerInterface (by default SimpleWalker). All following methods take an optional class that implements WalkerInterface to override the SimpleWalker.
Use
Reading
ReadingInterface
All reading related operations are done by an instance of ReaderInterface (by default ReaderWalker).
ReaderInterface implementation needs a WalkerInterface implementation to work.
All following methods take two optional parameters :
- class that implements ReaderInterface to override the SimpleReader.
- class that implements WalkerInterface to override the SimpleWalker.
Use
All those methods reset the pointer to its previous position. In other words it does not move the internal pointer.
Writing
WritingInterface
All walking related operations are done by an instance of WriterInterface (by default PrependingWriter which will not erase while writing).
Another writer available is ErasingWriter which will erase the content while writing (same behaviour as Insert keyboard).
All following methods take an optional class that implements WriterInterface to override the PrependingWriter.
Use
<?php
$textFile = new TextFile('text_file.txt');
// Write without erasing without return line break at the end
$textFile->write('test');
// Write without erasing with return line break at the end
$textFile->write('test', true);
// Write with erasing without return line break at the end
$textFile->write('test', false, TextFile\Writer::class);
// Write with erasing with return line break at the end
$textFile->write('test', true, TextFile\Writer::class);