PHP - yaml_parse() Function
The yaml_parse() function can parse a YAML stream.
Syntax
mixed yaml_parse( string $input [, int $pos = 0 [, int &$ndocs [, array $callbacks = null ]]] )
The yaml_parse() function can convert all or part of a YAML document stream to a PHP variable.
The yaml_parse() function can return a value encoded in input in appropriate PHP type or false on failure. If pos is -1, an array can be returned with one entry for each document found in a stream.
Example
<?php
$yaml = <<<EOD
---
invoice: 34843
date: "2001-01-23"
bill-to: &id001
given: Chris
family: Dumars
address:
lines: |-
458 Walkman Dr.
Suite #292
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;
$parsed = yaml_parse($yaml);
var_dump($parsed);
?>
php_function_reference.htm
Advertisements