PHP - yaml_parse() 函式



yaml_parse() 函式可以解析 YAML 流。

語法

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

yaml_parse() 函式可以將 YAML 文件流的全部或部分內容轉換為 PHP 變數。

yaml_parse() 函式可以返回以適當的 PHP 型別編碼的輸入值,或者在失敗時返回 false。如果 pos 為 -1,則可以返回一個數組,其中包含在流中找到的每個文件的一個條目。

示例

<?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
廣告