axp-dev / file-parser
File Parser Library for PHP
2.4.0
2023-05-28 09:14 UTC
Requires
- php: >=5.6.4
- symfony/yaml: 3.4.x-dev
Requires (Dev)
- illuminate/support: 5.4.*
README
File Parser Library for PHP. List of formats: json, xml, query string, serialize, ini, csv.
Contents
Installation
Composer
$ composer require axp-dev/file-parser
Laravel
Add service provider within app/config/app.php
:
'providers' => [ ... AXP\FileParser\FileParserServiceProvider::class ]
Add a facade alias:
'aliases' => [ ... 'FileParser' => AXP\FileParser\Facades\FileParser::class ]
Lumen
Add service provider within bootstrap/app.php
:
$app->register('AXP\FileParser\FileParserServiceProvider');
Add a facade alias:
class_alias('AXP\FileParser\Facades\FileParser', 'FileParser');
Usage
JSON
FileParser::json($string) : array
Example
$string = '{"id":1,"name":"A green door","price":12.5,"tags":["home","green"]}'; $data = FileParser::json($string); print_r($data);
XML
FileParser::xml($string) : array
Example
$string = '<?xml version="1.0" encoding="UTF-8" ?> <card> <id>1</id> <name>A green door</name> <price>12.5</price> <tags>home</tags> <tags>green</tags> </card>'; $data = FileParser::xml($string); print_r($data);
Query String
FileParser::queryString($string) : array
Example
$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
FileParser::serialize($string) : array
Example
$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
FileParser::ini($string) : array
Example
$string = '[card] id = 1 name = "A green door" price = 12.5 tags[] = home tags[] = green'; $data = FileParser::ini($string); print_r($data);
CSV
FileParser::csv($string, $delimiter = ';') : array
Example
$string = 'Title1;Title2;Title3 one;two;three example1;example2;example3'; $data = FileParser::csv($string); print_r($data);
YAML
FileParser::yaml($string) : array
Example
$string = 'latitude: 52.7157856867271 longitude: -8.8741735070805 zoom: 15'; $data = FileParser::yaml($file); print_r($data);
Author
Alexander Pushkarev, e-mail: axp-dev@yandex.com
License
Open-sourced software licensed under the MIT license