當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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 類型編碼的值或失敗時返回的值。如果 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 - yaml_parse() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。