https://github.com/victormech/ditesto
Object Oriented library to manipulate text files with PHP
https://github.com/victormech/ditesto
object-oriented php textfile
Last synced: about 1 month ago
JSON representation
Object Oriented library to manipulate text files with PHP
- Host: GitHub
- URL: https://github.com/victormech/ditesto
- Owner: victormech
- License: mit
- Created: 2016-04-07T03:27:46.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-10-26T04:57:03.000Z (over 8 years ago)
- Last Synced: 2026-01-28T07:53:42.753Z (5 months ago)
- Topics: object-oriented, php, textfile
- Language: PHP
- Homepage:
- Size: 85.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DiTesto
[](https://travis-ci.org/victormech/ditesto) [](https://scrutinizer-ci.com/g/victormech/ditesto/?branch=master) [](https://scrutinizer-ci.com/g/victormech/ditesto/?branch=master) [](https://www.codacy.com/app/victormech/ditesto) [](https://packagist.org/packages/lazyeight/ditesto)
##### A simple Object Oriented library to load and manipulate text files. Made using only PHP.
PHP minimum version: 7
## Usage
```php
$file = '/home/user/text-file.txt';
$fileSystem = new FileSystemHandler($file);
$textFile = new TextFile($file);
(new FileReader($textFile, $fileSystem))->readFile();
echo $textFile; // prints all file content
```
You can iterate line per line if you want:
```php
$textFile = new TextFile($file);
$fileSystem = new FileSystemHandler($file);
(new FileReader($textFile, $fileSystem))->readFile());
foreach ($textFile as $line) {
echo $line;
}
```
Or even like an Array:
```php
$textFile[] = new Line('Adding a new line');
$textFile[0] = new Line('Changing an existent line');
echo count($textFile); // prints total of lines
echo $textFile[1]; // prints only the second line
```
To persist the file changes:
```php
$textFile = new TextFile($file);
$fileSystem = new FileSystemHandler($file);
(new FileWriter($textFile, $fileSystem))->writeFile();
```
## License
The MIT License (MIT). Please see [License File](https://github.com/victormech/basic-types/blob/master/LICENSE) for more information.