PHP - Fonction yaml_parse ()

La fonction yaml_parse () peut analyser un flux YAML.

Syntaxe

mixed yaml_parse( string $input [, int $pos = 0 [, int &$ndocs [, array $callbacks = null ]]] )

La fonction yaml_parse () peut convertir tout ou partie d'un flux de documents YAML en une variable PHP.

La fonction yaml_parse () peut renvoyer une valeur encodée en entrée dans le type PHP approprié ou false en cas d'échec. Si pos vaut -1, un tableau peut être retourné avec une entrée pour chaque document trouvé dans un flux.

Exemple

<?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);
?>