Page 1 of 1
PHP arrays to yaml
Posted: Fri May 15, 2009 8:18 am
by shiznatix
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?
Re: PHP arrays to yaml
Posted: Fri May 15, 2009 8:23 am
by Benjamin
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.
Re: PHP arrays to yaml
Posted: Fri May 15, 2009 8:51 am
by shiznatix
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:
Code: Select all
private function _dataToYAML($array)
{
$yaml = "---\n";
foreach ($array as $key => $val)
{
$yaml .= ":".$key.": ".$val."\n";
}
return $yaml;
}
so you know, I guess that works. Still wish there was something better than this.
Re: PHP arrays to yaml
Posted: Mon Feb 15, 2010 10:39 pm
by the_last_tamurai
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/