icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.

» Surpass Web Hosting Forums » Discussions » PHP, MySQL » Fun with YAML (it ain't markup language)

PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >>

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
Old September 3rd, 2005, 2:04 PM   #1 (permalink)
Surpass Fan
On a golden path...
 
Joined in Nov 2004
Lives in San Francisco
364 posts
Gave thanks: 0
Thanked 3 times
Fun with YAML (it ain't markup language)

YAML (sounds like 'camel') is a human friendly data serialization language with a recursive name of YAML Ain't Markup Language. It can be used to write arrays and other fun data types in plain text (Unicode), and can be understood by a number of these dynamic languages we've got floating around. Perl, Python, PHP, Ruby, etc. See www.yaml.org for more info.

Here's an example of a nice, human friendly YAML document.
Code:
--- 
name: Admiral ozmm
age: 20 
residency: San Francisco 
loves: 
  - PHP 
  - Ruby 
  - Playing Guitar 
hates: [Gas Masks, Zombies]
Now I load the YAML into an array, maybe with $array = Spyc::YAMLLoad($yamlFile), and a print_r($array) comes out as:
PHP Code:
Array 

    [
name] => Admiral ozmm 
    
[age] => 20 
    
[residency] => San Francisco 
    
[loves] => Array 
        ( 
            [
0] => PHP 
            
[1] => Ruby 
            
[2] => Playing Guitar 
        

    [
hates] => Array 
        ( 
            [
0] => Gas Masks 
            
[1] => Zombies 
        



Think of the possibilities. No more confusing config files for your clients, easily understood log files (you can dump PHP arrays to YAML), the works.

If you're into the whole PHP thing, there is a pure PHP loader/dumper for YAML, called Spyc [spice] (a simple php yaml class). The project page is http://sourceforge.net/projects/spyc/. It's a newborn, so handle with care. If you want to lend a hand, it would be most appreciated.

See Spyc in action under the demo section of http://ozmm.org/spyc/

A super-fast extension written in C for PHP (and other languages) is Syck. You can get it at www.whytheluckystiff.net/syck/. If you are using Ruby, you already have Syck (YAML support is built into Ruby's standard library).
ghostcop is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 4th, 2005, 6:13 AM   #2 (permalink)
L'Awesome Advocate
Super #1
 
Ancyru's Avatar
 
Joined in May 2004
Lives in .au
Hosted on Mango
2,423 posts
Gave thanks: 1
Thanked 5 times
Wow, that looks like it can save a lot of time and help out some n00bs like me.
__________________
When I get sad, I stop being sad, and be AWESOME instead. True story.
Ancyru is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 4th, 2005, 6:20 AM   #3 (permalink)
is scientific.
Resident.
 
David's Avatar
 
Joined in Mar 2004
Lives in fear of Obama.
Hosted on Pass 7
13,117 posts
Gave thanks: 8
Thanked 34 times
maybe it's just a typo, but why is the hates in the friendly version in brackets? there doesn't seem to be a code reason in the code version. same with the loves having - beside them.
__________________
Quote:
Originally Posted by removed View Post
Internet Explorer rules.
David is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 4th, 2005, 10:54 AM   #4 (permalink)
SurPerson
On a golden path...
 
TJ09's Avatar
 
Joined in Jul 2004
Lives in front of my laptop
Hosted on Sync
437 posts
Gave thanks: 0
Thanked 1 Time in 1 Post
The example is probably just showing different ways of storing data using YAML, since apparantly both end up read the same way.
__________________
Me: TeeJay
Server: Sync (Statistics)
Site: technoized.com (Statistics)

chown -R us ./base
TJ09 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 4th, 2005, 12:27 PM   #5 (permalink)
Surpass Fan
On a golden path...
 
Joined in Nov 2004
Lives in San Francisco
364 posts
Gave thanks: 0
Thanked 3 times
There are many different ways to do many different things with YAML. It is an impressive spec, and the document I've shown is only a very small subset of the language. Sequences (indexed arrays) can indeed be written as multi-line dashed statements or as elements enclosed within brackets.

http://yaml.kwiki.org/?YamlInFiveMinutes is a good place to look over YAML, in five minutes.
ghostcop is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On