PHP YAML Parsers [closed]

2019-01-08 05:02发布

Does anyone know of a good YAML Parser for PHP? If so, what are the pros and cons of this library?

标签: php parsing yaml
8条回答
女痞
2楼-- · 2019-01-08 05:23

I'd suggest the process followed in this article http://devzone.zend.com/article/2585-using-yaml-with-php-and-pecl

查看更多
Summer. ? 凉城
3楼-- · 2019-01-08 05:25

Try sfYaml, it is the best I know.

Symfony and Doctrine ORM are using this one.

To get it, you may Download Doctrine 1.2 and extract sfYaml from vendor directory.

Let us know if it suits your needs.

查看更多
Emotional °昔
4楼-- · 2019-01-08 05:26

If you need to test your YAML quickly, I built: http://yaml-online-parser.appspot.com/ . It helps me write YAML, especially while just learning.

查看更多
乱世女痞
5楼-- · 2019-01-08 05:29

Symfony2 has a YAML component which supports most of the YAML 1.2 spec

https://github.com/symfony/Yaml

查看更多
▲ chillily
6楼-- · 2019-01-08 05:31

If you're using a lot of YAML in your project you may find that the pure PHP libraries like spyc or Symfony YAML are not fast enough. There are at least two PHP bindings for C YAML parsers:

  • yaml - a wrapper for the LibYAML YAML 1.1 parser library
  • syck - a wrapper for the Syck YAML 1.0 parser library
查看更多
神经病院院长
7楼-- · 2019-01-08 05:35

Spyc: https://github.com/mustangostang/spyc

Pure PHP implementation, so you don't need to make any modifications to the server for installation. If speed is of dire concern, it might not be the ideal solution, but if you're using YAML for configurations or relatively low-volume use, it is a fantastic solution.

Given a YAML document, Spyc will return an array that you can use however you see fit.

require_once "spyc.php";
$data = Spyc::YAMLLoad($myfile);

Given an array, Spyc will return a string which contains a YAML document built from your data.

$yaml_str = Spyc::YAMLDump($myarray);
查看更多
登录 后发表回答