izzy-p/laravel-formatter
一个格式化库,用于在XML、CSV、JSON、TXT、YAML和其他几种格式之间转换数据输出。
2.0
2014-10-20 15:15 UTC
Requires
- php: >=5.4.0
- illuminate/support: >=4.0
- league/csv: ~6.0
- mustangostang/spyc: 0.5.*@dev
This package is not auto-updated.
Last update: 2024-09-14 17:37:16 UTC
README
一个格式化包,可以帮助您轻松地在各种格式之间进行转换,例如XML、JSON、CSV等...
目标
该库的目标是允许数据格式从一种类型转换为另一种类型。请参阅“解析器和格式”部分,了解支持的输入/输出格式。
安装
通过命令行
composer require IzzyP/laravel-formatter
通过composer.json
{ "require": { "IzzyP/laravel-formatter": "2.x" } }
解析器
以下所有格式都是格式化库可以读取的格式。
- 数组
- CSV
- JSON
- XML
- YAML
格式
以下所有格式都是支持的输出格式。
- 数组
- CSV
- JSON
- XML
- YAML
常规用法
包含格式化工具
use IzzyP\Formatter\Formatter;
支持类型
Formatter::JSON; //json Formatter::CSV; //csv Formatter::XML; //xml Formatter::ARR; //array Formatter::YAML; //yaml
创建您的第一个格式化器
$formatter = Formatter::make($jsonString, Formatter::JSON); $formatter = Formatter::make($yamlString, Formatter::YAML); $formatter = Formatter::make($array, Formatter::ARR); ...
从格式化器输出
$csv = $formatter->toCsv(); $json = $formatter->toJson(); $xml = $formatter->toXml(); $array = $formatter->toArray(); $yaml = $formatter->toYaml();
已弃用功能
以下功能已被从库中弃用,但是您可以在应用程序中轻松继续使用它们
序列化数组
$serialized = serialize($formatter->toArray());
PHP导出
$export = var_export($formatter->toArray());