How to convert a yaml to PHP array?

Asked

Viewed 230 times

3

How could I do to convert data yaml in a array of PHP?

Yaml example:

Usuario:
    nome: Wallace
    idade: 25
    linguagens: 
        - PHP
        - Python
        - Javascript

2 answers

5

A good way would be using the Yaml Component of Symphony.

Behold:

use Symfony\Component\Yaml\Parser;

$yaml = new Parser();

$value = $yaml->parse(file_get_contents('/arquivo.yml'));

Reference: The Yaml Component

  • 1

    +1 for the symfony

  • I really like the Symphony. It’s a pity that most systems are already written here in Laravel 4 (that’s not bad either)

4


Browser other questions tagged

You are not signed in. Login or sign up in order to post.