memo.xight.org

日々のメモ

spyc - PHPでYAMLを扱えるライブラリ

用途

オプションファイルを YAML で記述.
オプションファイルの編集に PHP を利用.

YAML から 配列に

include('spyc.php');

$array = Spyc::YAMLLoad('yamlfile.yml');
print_r($array);


配列 から YAML に

include('spyc.php');

$array[] = 'Sequence item';
$array['The Key'] = 'Mapped value';
$array[] = array('A sequence','of a sequence');
$array[] = array('first' => 'A sequence','second' => 'of mapped values');
$array['Mapped'] = array('A sequence','which is mapped');
$array['A Note'] = 'What if your text is too long?';
$array['Another Note'] = 'If that is the case, the dumper will probably fold your text by using a block.  Kinda like this.';
$array['The trick?'] = 'The trick is that we overrode the default indent, 2, to 4 and the default wordwrap, 40, to 60.';
$array['Old Dog'] = "And if you want\n to preserve line breaks, \ngo ahead!";

$yaml = Spyc::YAMLDump($array,4,60);
print_r($yaml);


Reference

SourceForge - spyc: a simple php yaml class
http://spyc.sourceforge.net/

cl.pocari.org - 人間にとって読みやすいデータ直列化フォーマット YAML Ain't Markup Language
http://cl.pocari.org/2005-10-20-1.html
NamingSense::TokuLog! - YAMLでヴァリデーションの条件を書く
http://d.hatena.ne.jp/tokuhirom/20060310/1142007501

via

phpspot開発日誌 - PHP用YAMLクラス : spyc
http://phpspot.org/blog/archives/2006/02/phpyaml_spyc.html