macromindonline / 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-18 03:22:28 UTC
README
一个格式化包,可以帮助您轻松地在各种格式之间进行转换,如XML、JSON、CSV等...
目标
该库的目标是允许数据格式从一个类型转换到另一个类型。请参阅解析器和格式以查看支持的输入/输出格式。
安装
通过命令行
composer require soapbox/laravel-formatter
通过composer.json
{
"require": {
"soapbox/laravel-formatter": "2.x"
}
}
解析器
以下都是格式化库可以从中读取的受支持格式。
- 数组
- CSV
- JSON
- XML
- YAML
格式
以下都是受支持的输出格式。
- 数组
- CSV
- JSON
- XML
- YAML
通用用法
包含格式化器
use SoapBox\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());