|
1 | 1 | # PHP DSV Reader & Writer
|
2 | 2 |
|
3 |
| -[Why you should use and prefer DSV format instead of CSV?](https://matthodges.com/posts/2024-08-12-csv-bad-dsv-good/) |
| 3 | +Inspired by: [Why you should use and prefer DSV format instead of CSV](https://matthodges.com/posts/2024-08-12-csv-bad-dsv-good/) |
4 | 4 |
|
5 |
| -[](https://app.codecov.io/gh/terremoth/vendor) |
6 |
| -[](https://shepherd.dev/github/terremoth/vendor) |
7 |
| -[](https://shepherd.dev/github/terremoth/vendor) |
8 |
| -[](https://github.com/terremoth/vendor/actions/workflows/workflow.yml) |
9 |
| -[](https://app.codacy.com/gh/terremoth/vendor/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) |
10 |
| -[](https://codeclimate.com/github/terremoth/vendor/maintainability) |
11 |
| -[](https://github.com/terremoth/vendor/blob/main/LICENSE) |
| 5 | +[](https://app.codecov.io/gh/terremoth/php-dsv) |
| 6 | +[](https://shepherd.dev/github/terremoth/php-dsv) |
| 7 | +[](https://shepherd.dev/github/terremoth/php-dsv) |
| 8 | +[](https://github.com/terremoth/php-dsv/actions/workflows/workflow.yml) |
| 9 | +[](https://app.codacy.com/gh/terremoth/php-dsv/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) |
| 10 | +[](https://codeclimate.com/github/terremoth/php-dsv/maintainability) |
| 11 | +[](https://github.com/terremoth/php-dsv/blob/main/LICENSE) |
12 | 12 |
|
13 |
| -See [demos/demo.php](demos/demo.php) for examples. |
| 13 | +See [demos/demo.php](demos/demo.php) for examples. |
14 | 14 |
|
15 | 15 | ## Installation
|
| 16 | + |
| 17 | +```shell |
| 18 | +composer require terremoth/php-dsv --no-dev |
| 19 | +``` |
| 20 | + |
| 21 | +## Usage: |
| 22 | + |
| 23 | +```php |
| 24 | +require_once 'vendor/autoload.php'; |
| 25 | + |
| 26 | +use DSV\DSVWriter; |
| 27 | +use DSV\DSVReader; |
| 28 | + |
| 29 | +$data = [ |
| 30 | + ['Name', 'Comment'], |
| 31 | + ['Alice', 'She said, "Hello" and waved.'], |
| 32 | + ['Bob', 'This is a multi-line comment\r\nspanning two lines.'], |
| 33 | + ['Charlie', 'More fun with\ntwo lines.'], |
| 34 | + ['Diana', 'How about some UTF-8: café, naïve, résumé. 📝'], |
| 35 | + ['Edward', 'アップル'], |
| 36 | +]; |
| 37 | + |
| 38 | +$writer = new DSVWriter('demos/data.dsv'); |
| 39 | +$writer->write($data); // will write the $data to file in DSV format |
| 40 | + |
| 41 | +$reader = new DSVReader('demos/data.dsv'); |
| 42 | +print_r($reader->read()); // will read the demos/data.dsv file and put it in array format |
| 43 | +``` |
0 commit comments