xref: /plugin/statistics/vendor/mustangostang/spyc/examples/yaml-dump.php (revision d5ef99ddb7dfb0cfae33e9257bd1d788f682c50f)
1*d5ef99ddSAndreas Gohr<?php
2*d5ef99ddSAndreas Gohr
3*d5ef99ddSAndreas Gohr#
4*d5ef99ddSAndreas Gohr#    S P Y C
5*d5ef99ddSAndreas Gohr#      a simple php yaml class
6*d5ef99ddSAndreas Gohr#
7*d5ef99ddSAndreas Gohr# Feel free to dump an array to YAML, and then to load that YAML back into an
8*d5ef99ddSAndreas Gohr# array.  This is a good way to test the limitations of the parser and maybe
9*d5ef99ddSAndreas Gohr# learn some basic YAML.
10*d5ef99ddSAndreas Gohr#
11*d5ef99ddSAndreas Gohr
12*d5ef99ddSAndreas Gohrinclude('../Spyc.php');
13*d5ef99ddSAndreas Gohr
14*d5ef99ddSAndreas Gohr$array[] = 'Sequence item';
15*d5ef99ddSAndreas Gohr$array['The Key'] = 'Mapped value';
16*d5ef99ddSAndreas Gohr$array[] = array('A sequence','of a sequence');
17*d5ef99ddSAndreas Gohr$array[] = array('first' => 'A sequence','second' => 'of mapped values');
18*d5ef99ddSAndreas Gohr$array['Mapped'] = array('A sequence','which is mapped');
19*d5ef99ddSAndreas Gohr$array['A Note'] = 'What if your text is too long?';
20*d5ef99ddSAndreas Gohr$array['Another Note'] = 'If that is the case, the dumper will probably fold your text by using a block.  Kinda like this.';
21*d5ef99ddSAndreas Gohr$array['The trick?'] = 'The trick is that we overrode the default indent, 2, to 4 and the default wordwrap, 40, to 60.';
22*d5ef99ddSAndreas Gohr$array['Old Dog'] = "And if you want\n to preserve line breaks, \ngo ahead!";
23*d5ef99ddSAndreas Gohr$array['key:withcolon'] = "Should support this to";
24*d5ef99ddSAndreas Gohr
25*d5ef99ddSAndreas Gohr$yaml = Spyc::YAMLDump($array,4,60);
26