Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/takuya/php-stringio
https://github.com/takuya/php-stringio
Last synced: 21 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/takuya/php-stringio
- Owner: takuya
- License: other
- Created: 2021-08-23T01:54:15.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2021-08-23T02:05:55.000Z (about 3 years ago)
- Last Synced: 2024-10-13T18:53:29.177Z (about 1 month ago)
- Language: PHP
- Size: 6.84 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# StringIO
![](https://circleci.com/gh/takuya/php-stringio.svg?style=svg)
'string' as IO Stream Object. To avoid large string split into large array.
Needless to say,`SplFileObject('php://memory','w+')` is best, but too much.
## Installation
```
composer requore takuya/php-stringio
```## Usage
```php
$sio = new StringIO("1234\n");
$sio->write("aaaa\n");
$sio->write("bbbb\n");
$sio->write("cccc\n");
$sio->rewind();
foreach ( $sio->lines() as $line) {
var_dump($line);
}
$sio->close();
```### Same to SplFileObject
```php
$sio = new \SplFileObject('php://memory','w+');
$sio->fwrite("1234\n");
$sio->fwrite("aaaa\n");
$sio->fwrite("bbbb\n");
$sio->fwrite("cccc\n");
foreach ( $sio as $line) {
var_dump(trim($line));
}
unset($sio);
```
[SplFileObject](https://www.php.net/manual/en/class.splfileobject.php) has too much inherited method.### Differences to SplFileObject
- trim() -- no new line(s such as "\r","\n")
- few methods -- no inherited methods
- f- prefix -- without f- ( fwrite/write )
- yield -- generator in lines()
- close -- SplFileObject does not have fclose()### Methods
- StringIO#rewind
- StringIO#seek
- StringIO#tell
- StringIO#resource
- StringIO#close
- StringIO#closed
- StringIO#readline
- StringIO#gets
- StringIO#write
- StringIO#get_contents
- StringIO#eof
- StringIO#lines
- StringIO#get_meta_data
- StringIO#__toString