Giter VIP home page Giter VIP logo

fileparser's Introduction

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: [email protected]

License

Open-sourced software licensed under the MIT license

fileparser's People

Contributors

axp-dev avatar podluzhnyi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.