SomeLuigi(2012-06-06 09:57:25)So today, I got the YAML parser/emitter.
A big question that you guys will have today is: What IS YAML, SomeLuigi?
YAML (stands for "YAML Ain't Markup Language", yes, another recursive acronym), is a means to store information in a human-readable fashion.
Some of you may know that I love the serialize() and unserialize() functions in PHP (PHP: Hypertext Preprocessor, recursive acronym).
There is three BIG downsides to this though:
1) The information is somewhat difficult to read
2) If you want to edit a value (example: string), you might have to type in how long it is aswell.
3) Not a lot of other programming languages have parse/emit layers for this format.
Then the other day, I came across YAML (.yml file extension).
I had a look at some examples of these files I had on disk, and sure enough, they were easy to read!
I added the spyc package to the /lib/ folder.
Stuff you need to know:
Spyc::YAMLLoad(filename)
- load from filename
Spyc::YAMLLoadString(yamlsource)
- load from source string
/**
* Dump YAML from PHP array statically
*
* The dump method, when supplied with an array, will do its best
* to convert the array into friendly YAML. Pretty simple. Feel free to
* save the returned string as nothing.yaml and pass it around.
*
* Oh, and you can decide how big the indent is and what the wordwrap
* for folding is. Pretty cool -- just pass in 'false' for either if
* you want to use the default.
*
* Indent's default is 2 spaces, wordwrap's default is 40 characters. And
* you can turn off wordwrap by passing in 0.
*
* @access public
* @return string
* @param array $array PHP array
* @param int $indent Pass in false to use the default, which is 2
* @param int $wordwrap Pass in 0 for no wordwrap, false for default (40)
*/
public static function YAMLDump($array,$indent = false,$wordwrap = false) { ...
And finally, it's in /lib/spyc.php
I know I'll be using this
This post has been edited one or more times, the last time was: 2012-06-06 09:58:01
SomeLuigi is changing in 2015.
SomeLuigi(2012-06-07 20:33:54)For storing data in files -Cartiga
So today, I got the YAML parser/emitter.
A big question that you guys will have today is:
What IS YAML, SomeLuigi?
YAML (stands for "YAML Ain't Markup Language", yes, another recursive acronym), is a means to store information in a human-readable fashion.
Some of you may know that I love the serialize() and unserialize() functions in PHP (PHP: Hypertext Preprocessor, recursive acronym).
There is three BIG downsides to this though:
1) The information is somewhat difficult to read
2) If you want to edit a value (example: string), you might have to type in how long it is aswell.
3) Not a lot of other programming languages have parse/emit layers for this format.
Then the other day, I came across YAML (.yml file extension).
I had a look at some examples of these files I had on disk, and sure enough, they were easy to read!
I added the spyc package to the /lib/ folder.
Stuff you need to know:
Spyc::YAMLLoad(filename)
- load from filename
Spyc::YAMLLoadString(yamlsource)
- load from source string
Spyc::YAMLDump($array, $indent, $wordwrap)
* Dump YAML from PHP array statically
*
* The dump method, when supplied with an array, will do its best
* to convert the array into friendly YAML. Pretty simple. Feel free to
* save the returned string as nothing.yaml and pass it around.
*
* Oh, and you can decide how big the indent is and what the wordwrap
* for folding is. Pretty cool -- just pass in 'false' for either if
* you want to use the default.
*
* Indent's default is 2 spaces, wordwrap's default is 40 characters. And
* you can turn off wordwrap by passing in 0.
*
* @access public
* @return string
* @param array $array PHP array
* @param int $indent Pass in false to use the default, which is 2
* @param int $wordwrap Pass in 0 for no wordwrap, false for default (40)
*/
public static function YAMLDump($array,$indent = false,$wordwrap = false) { ...
And finally, it's in /lib/spyc.php
I know I'll be using this
2012-06-06 09:58:01