Is there a decent php library that can do array to yaml and yaml to array? I have tried spyc but it only does yaml to php, not the other way around. I have tried to install the php5-yaml package but its only in sid and on our live server it just isn't there and I don't want to start screwing around with that.
So, is there no decent extension or library that can do this?
PHP arrays to yaml
Moderator: General Moderators
Re: PHP arrays to yaml
I did a quick search and didn't really see anything, although more than likely there is something out there. I'd probably just write something myself in order to do an array to yaml conversion. It would be fairly simple I imagine.
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
Re: PHP arrays to yaml
same, can't find anything on google. Since the arrays that I am converting are quite simple I did just write my own. It looks like this:
so you know, I guess that works. Still wish there was something better than this.
Code: Select all
private function _dataToYAML($array)
{
$yaml = "---\n";
foreach ($array as $key => $val)
{
$yaml .= ":".$key.": ".$val."\n";
}
return $yaml;
}
- the_last_tamurai
- Forum Commoner
- Posts: 87
- Joined: Wed Feb 28, 2007 8:24 am
- Location: cairo
- Contact:
Re: PHP arrays to yaml
I know it's very late, but I just see the topic 
and maybe it can help someone
see this component http://components.symfony-project.org/yaml/
and maybe it can help someone
see this component http://components.symfony-project.org/yaml/