Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hywax/fileparser
File Parser Library for PHP. List of formats: json, xml, query string, serialize, ini, csv, yaml
https://github.com/hywax/fileparser
csv files json parse parser query-string serialize xml yaml
Last synced: 3 months ago
JSON representation
File Parser Library for PHP. List of formats: json, xml, query string, serialize, ini, csv, yaml
- Host: GitHub
- URL: https://github.com/hywax/fileparser
- Owner: hywax
- License: mit
- Created: 2017-07-20T12:16:23.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-05-28T10:10:54.000Z (over 1 year ago)
- Last Synced: 2024-03-06T16:15:30.156Z (11 months ago)
- Topics: csv, files, json, parse, parser, query-string, serialize, xml, yaml
- Language: PHP
- Homepage:
- Size: 25.4 KB
- Stars: 5
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# File Parser
[![Latest Stable Version](https://poser.pugx.org/axp-dev/file-parser/v/stable)](https://packagist.org/packages/axp-dev/file-parser)
[![Latest Unstable Version](https://poser.pugx.org/axp-dev/file-parser/v/unstable)](https://packagist.org/packages/axp-dev/file-parser)
[![License](https://poser.pugx.org/axp-dev/file-parser/license)](https://packagist.org/packages/axp-dev/file-parser)File Parser Library for PHP. List of formats: json, xml, query string, serialize, ini, csv.
## Contents
1. [Installation](#installation)
+ [Composer](#composer)
+ [Laravel](#laravel)
+ [Lumen](#lumen)
2. [Usage](#usage)
+ [JSON](#json)
+ [XML](#xml)
+ [Query String](#query-string)
+ [Serialize](#serialize)
+ [INI](#ini)
+ [CSV](#csv)
+ [YAML](#yaml)
3. [Author](#author)
4. [License](#license)## Installation
#### Composer
```
$ composer require axp-dev/file-parser
```
#### Laravel
Add service provider within `app/config/app.php`:
```php
'providers' => [
...
AXP\FileParser\FileParserServiceProvider::class
]
```
Add a facade alias:
```php
'aliases' => [
...
'FileParser' => AXP\FileParser\Facades\FileParser::class
]
```
#### Lumen
Add service provider within `bootstrap/app.php`:
```php
$app->register('AXP\FileParser\FileParserServiceProvider');
```
Add a facade alias:
```php
class_alias('AXP\FileParser\Facades\FileParser', 'FileParser');
```## Usage
### JSON
```php
FileParser::json($string) : array
```
#### Example
```php
$string = '{"id":1,"name":"A green door","price":12.5,"tags":["home","green"]}';
$data = FileParser::json($string);print_r($data);
```### XML
```php
FileParser::xml($string) : array
```
#### Example
```php
$string = '
1
A green door
12.5
home
green
';
$data = FileParser::xml($string);print_r($data);
```### Query String
```php
FileParser::queryString($string) : array
```
#### Example
```php
$string = 'id=1&name=A+green+door&price=12.5&tags%5B0%5D=home&tags%5B1%5D=green';
$data = FileParser::queryString($string);print_r($data);
```### Serialize
```php
FileParser::serialize($string) : array
```
#### Example
```php
$string = 'a:4:{s:2:"id";s:1:"1";s:4:"name";s:12:"A green door";s:5:"price";s:4:"12.5";s:4:"tags";a:2:{i:0;s:4:"home";i:1;s:5:"green";}}';
$data = FileParser::serialize($string);print_r($data);
```### INI
```php
FileParser::ini($string) : array
```
#### Example
```php
$string = '[card]
id = 1
name = "A green door"
price = 12.5
tags[] = home
tags[] = green';
$data = FileParser::ini($string);print_r($data);
```### CSV
```php
FileParser::csv($string, $delimiter = ';') : array
```
#### Example
```php
$string = 'Title1;Title2;Title3
one;two;three
example1;example2;example3';
$data = FileParser::csv($string);print_r($data);
```### YAML
```php
FileParser::yaml($string) : array
```
#### Example
```php
$string = 'latitude: 52.7157856867271
longitude: -8.8741735070805
zoom: 15';
$data = FileParser::yaml($file);print_r($data);
```## Author
[Alexander Pushkarev](https://github.com/axp-dev), e-mail: [[email protected]](mailto:[email protected])## License
Open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT)