axp-dev / FileParser by AXP

File Parser Library for PHP
10,461
5
2
Package Data
Maintainer Username: AXP
Maintainer Contact: axp-dev@yandex.com (Alexander Pushkarev)
Package Create Date: 2017-07-20
Package Last Update: 2023-05-28
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-12-16 15:03:07
Package Statistics
Total Downloads: 10,461
Monthly Downloads: 666
Daily Downloads: 37
Total Stars: 5
Total Watchers: 2
Total Forks: 4
Total Open Issues: 1

File Parser

Latest Stable Version Latest Unstable Version License

File Parser Library for PHP. List of formats: json, xml, query string, serialize, ini, csv.

Contents

  1. Installation
  2. Usage
  3. Author
  4. License

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