вот что намудрил...
выставляю на всеобщую критику
class Yaml
{
@param @return
private function cleanup($value)
{
$value = str_replace([("\r\n", "\r")], "\n", $value);
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#u', '', $value);
$value = preg_replace('#^(\#.*?\n)+#s', '', $value);
$value = preg_replace('#^\-\-\-.*?\n#s', '', $value);
$value = preg_replace('#\.\.\.\s*$#', '', $value);
return $value;
}
@param @return
public function arrayLine($str)
{
$line = explode("\n", $str);
foreach ($line as $val) {
$yaml_dec[] = preg_replace('#^-#', ' ', $val);
}
$i = 0;
foreach ($yaml_dec as $val) {
$yaml_array [] = explode(":", $val);
if (!empty($yaml_array[$i][1])) {
$var1[] = $yaml_array[$i][0];
$var2[] = $yaml_array[$i][1];
}
$i++;
}
$yaml = array_combine($var1, $var2);
return $yaml;
}
@param @return
public function parser($str)
{
$strline = $this->cleanup($str);
return $this->arrayLine($strline);
}
}
из такого yaml
$yaml = <<<EOD
#sdjfhhsdjk
invoice: 34843
date: "2001-01-23"
bill-to: &id001
given: Chris
family: Dumars
address:
city: Royal Oak
state: MI
postal: 48046
ship-to: *id001
product:
- sku: BL394D
quantity: 4
description: Basketball
price: 450
- sku: BL4438H
quantity: 1
description: Super Hoop
price: 2392
tax: 251.420000
total: 4443.520000
comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.
...
EOD;
можно получить
такой массив
Array
(
[invoice] => 34843
[date] => "2001-01-23"
[bill-to] => &id001
[ given] => Chris
[ family] => Dumars
[ city] => Royal Oak
[ state] => MI
[ postal] => 48046
[ship-to] => *id001
[ sku] => BL4438H
[ quantity] => 1
[ description] => Super Hoop
[ price] => 2392
[tax] => 251.420000
[total] => 4443.520000
[comments] => Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.
)