十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
在看drupal8,發(fā)現(xiàn)其模塊和主題的定義使用的是YAML文件。drupal8使用的Symfony框架中YAML文件結(jié)構(gòu),故翻譯整理學(xué)習(xí)下,有理解不準(zhǔn)確的地方請多多指教。

創(chuàng)新互聯(lián)建站為客戶提供專業(yè)的做網(wǎng)站、成都網(wǎng)站建設(shè)、程序、域名、空間一條龍服務(wù),提供基于WEB的系統(tǒng)開發(fā). 服務(wù)項目涵蓋了網(wǎng)頁設(shè)計、網(wǎng)站程序開發(fā)、WEB系統(tǒng)開發(fā)、微信二次開發(fā)、移動網(wǎng)站建設(shè)等網(wǎng)站方面業(yè)務(wù)。
String
一般字符串可以使用單引號,雙引號或者不使用引號。
A string in YAML 'A singled-quoted string in YAML' "A double-quoted string in YAML"
當(dāng)使用單引號字符串時,其內(nèi)容中的任何單引號必須加倍才能轉(zhuǎn)義:
'A single quote '' inside a single-quoted string'
包含以下任何字符都需要引號,可以使用單引號或雙引號,但使用單引號更方便
:, {, }, [, ], ,, &, *, #, ?, |, -, <, >, =, !, %, @, `
雙引號方式提供了以一種表示任意字符串的方法,使用\來轉(zhuǎn)義字符和序列
\0, \x01, \x02, \x03, \x04, \x05, \x06, \a, \b, \t, \n, \v, \f, \r, \x0e, \x0f, \x10, \x11, \x12, \x13, \x14, \x15, \x16, \x17, \x18, \x19, \x1a, \e, \x1c, \x1d, \x1e, \x1f, \N, \_, \L, \P
"A double-quoted string in YAML\n"
注:測試發(fā)現(xiàn),當(dāng)字符串中包含上面字符時,使用單引號也可以轉(zhuǎn)義的
最后還有其他一些情況,不管你使用單引號還是雙引號
true or false ( 否則就是布爾值 )
null or ~ (否則認為是null)
當(dāng)看起來像整數(shù)如2,14;浮點數(shù)如2.6,14.9;指數(shù)如12e7等,否則被視為一個數(shù)值
當(dāng)看起來像一個日期如2014-12-31,否則會自動轉(zhuǎn)為一個Unix時間戳
'true' 'null' '2.14' '2014-12-31'
當(dāng)一個字符串中包含換行符時,可以使用由(|)管道符來指示該字符串將跨越多行。在文字中,換行符被保存下來
| \/ /| |\/| | / / | | | |__
或者字符串可以使用折疊樣式編寫,用>表示,其中每行換行符被空格替換
> This is a very long sentence that spans several lines in the YAML but which will be rendered as a string without carriage returns.
12 #十進制 014 #八進制 0xC #十六進制 13.4 #浮點數(shù) 1.2e+24 #指數(shù) .inf #無窮
null ~
true false
#簡單日期 2002-12-14
- PHP - Perl - Python
對應(yīng)PHP為
array('PHP','perl','Python')PHP: 5.2 MySQL: 5.1 Apache: 2.2.20
對應(yīng)PHP為
array('PHP' => 5.2, 'MySQL' => 5.1, 'Apache' => '2.2.20');'symfony 1.0': PHP: 5.0 Propel: 1.2 'symfony 1.2': PHP: 5.2 Propel: 1.3
對應(yīng)PHP為
array( 'symfony 1.0' => array( 'PHP' => 5.0, 'Propel' => 1.2, ), 'symfony 1.2' => array( 'PHP' => 5.2, 'Propel' => 1.3, ), );
在YAML文件中使用縮進時需要記住一件重要的事情:縮進必須由一個或多個空格完成,但從不使用制表符。
也可以根據(jù)需要嵌套序列和映射
'Chapter 1': - Introduction - Event Types 'Chapter 2': - Introduction - Helpers
也可使用明顯的指示符而不是縮進
[PHP, Perl, Python]
{ PHP: 5.2, MySQL: 5.1, Apache: 2.2.20 }
'Chapter 1': [Introduction, Event Types]
'Chapter 2': [Introduction, Helpers]
'symfony 1.0': { PHP: 5.0, Propel: 1.2 }
'symfony 1.2': { PHP: 5.2, Propel: 1.3 }#comment on a line
Explicit Typingdata: # this value is parsed as a string (it's not transformed into a DateTime) start_date: !!str 2002-12-14 # this value is parsed as a float number (it will be 3.0 instead of 3) price: !!float 3 # this value is parsed as binary data encoded in base64 picture: !!binary | R0lGODlhDAAMAIQAAP//9/X 17unp5WZmZgAAAOfn515eXv Pz7Y6OjuDg4J+fn5OTk6enp
Unsupported YAML Features
Symfony Yaml組件不支持以下YAML特性:
Multi-documents (--- and ... markers); 多文檔(---和...標(biāo)記);
Complex mapping keys and complex values starting with ?;以?開頭的復(fù)雜映射鍵和復(fù)數(shù)值;
Tagged values as keys;標(biāo)記為鍵的值;
下面標(biāo)簽和類型: !!set, !!omap, !!pairs, !!set, !!seq, !!bool, !!int, !!merge, !!null, !!timestamp, !!value, !!yaml;
標(biāo)記(TAG指令;例如:%TAG!標(biāo)記:example.com,2000:app /)和標(biāo)記引用(例如:!
映射元素使用類似序列的語法(例如:{foo,bar};改為使用{foo:?,bar:?})
原文地址:http://symfony.com/doc/current/components/yaml/yaml_format.html
驗證地址:https://codebeautify.org/yaml-to-json-xml-csv
---
僅供個人理解參考