承接 pearl/csv-json-converter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pearl/csv-json-converter

Composer 安装命令:

composer require pearl/csv-json-converter

包简介

Convert CSV to JSON and JSON to CSV file format using PHP

README 文档

README

Build Status

Convert CSV to JSON and JSON to CSV using PHP.

Installation

composer require pearl/csv-json-converter

How to use?

JSON to CSV:

Sample Json Data:
$jsonString = '[{
    "name": "Half Girlfriend",
    "author": "Chetan Bhagat",
    "publisher": "Rupa Publications",
    "language": "en"
},
{
    "name": "My Journey: Transforming Dreams into Actions",
    "author": "A.P.J. Abdul Kalam",
    "publisher": "Rupa Publications",
    "language": "en"
}]';
use Pearl\CsvJsonConverter\Type\JsonToCsv;	
Data loading:
  • Array or Json values are accepted.
  • Custom output header optional available. This is optional parameter if not passed then default header will be considered.
$jsonToCsv = new JsonToCsv($jsonString, ['headers' => ["productName", "author", "publisher", "lang"]]);

Or load the json data from file.

$jsonToCsv->load(__Dir__ . '/data/products.json');
Data conversion result options :
<!-- Convert and save the result to specificed path -->
$jsonToCsv->convertAndSave(__Dir__ . '/output');

<!-- Convert and force download the file in browser-->
$jsonToCsv->convertAndDownload(__Dir__ . '/output');

<!-- Convert and get data-->
$jsonToCsv->convert();

Output:

name author publisher language
Half Girlfriend Chetan Bhagat Rupa Publications en
My Journey: Transforming Dreams into Actions A.P.J. Abdul Kalam Rupa Publications en

CSV to JSON:

use Pearl\CsvJsonConverter\Type\CsvToJson;

Load the CSV data.

$csvToJson = new CsvToJson($csvString, ['bitmask' => 'JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES']);

Or Load the csv data from file.

$csvToJson->load(__Dir__ . '/data/products.csv');
Data conversion result options :
<!-- Convert and save to specificed path -->
$csvToJson->convertAndSave(__Dir__ . '/output');

<!-- Convert and force download the file-->
$csvToJson->convertAndDownload(__Dir__ . '/output');

<!-- Convert and get data-->
$csvToJson->convert();

Sample Csv:

name author publisher language
Half Girlfriend Chetan Bhagat Rupa Publications en
My Journey: Transforming Dreams into Actions A.P.J. Abdul Kalam Rupa Publications en

Output:

  [{
  		"name": "Half Girlfriend",
  		"author": "Chetan Bhagat",
  		"publisher": "Rupa Publications",
  		"language": "en"
  	},
  	{
  		"name": "My Journey: Transforming Dreams into Actions",
  		"author": "A.P.J. Abdul Kalam",
  		"publisher": "Rupa Publications",
  		"language": "en"
  	}
  ]

统计信息

  • 总下载量: 5.78k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固