lazyeight / ditesto
使用PHP操作文本文件的面向对象库
v4.0.0
2017-10-26 04:51 UTC
Requires
- php: >=7
Requires (Dev)
- phpunit/phpunit: 6.*.*
This package is not auto-updated.
Last update: 2024-09-14 19:25:32 UTC
README
一个简单的面向对象库,用于加载和操作文本文件。仅使用PHP制作。
PHP最低版本:7
用法
$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
如果您想逐行迭代,可以这样做
$textFile = new TextFile($file); $fileSystem = new FileSystemHandler($file); (new FileReader($textFile, $fileSystem))->readFile()); foreach ($textFile as $line) { echo $line; }
或者就像数组一样
$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
以持久保存文件更改
$textFile = new TextFile($file); $fileSystem = new FileSystemHandler($file); (new FileWriter($textFile, $fileSystem))->writeFile();
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。