How could I do to convert yaml
data to a array
of PHP?
Example yaml:
Usuario:
nome: Wallace
idade: 25
linguagens:
- PHP
- Python
- Javascript
How could I do to convert yaml
data to a array
of PHP?
Example yaml:
Usuario:
nome: Wallace
idade: 25
linguagens:
- PHP
- Python
- Javascript
In the PHP Manual , you have an example:
$yaml = <<<EOD
Usuario:
nome: Wallace
idade: 25
linguagens:
- PHP
- Python
- Javascript
EOD;
$parsed = yaml_parse($yaml);
echo "<pre>";
print_r($parsed);
Just be sure to enable the extension: extension=yaml.so
on php.ini
A good way would be to use Yaml Component
of Symphony
.
See:
use Symfony\Component\Yaml\Parser;
$yaml = new Parser();
$value = $yaml->parse(file_get_contents('/arquivo.yml'));
Reference: The Yaml Component