Home > php教程 > php手册 > body text

让我们一起认识YAML:YAML简介

WBOY
Release: 2016-06-13 10:29:13
Original
1410 people have browsed it

YAML

来自YAML官方网站 (http://www.yaml.org/) 的定义: YAML是一种直观的能够被电脑识别的的数据数据序列化格式,它并且容易被人类阅读,容易与脚本语言交互的。换种说法,YAML是一种非常简单的类似于XML的数据描述语言,语法比XML简单很多。他在描述可以被转化成数组或者hash的数据是非常有用,例如:

$house = array(
  family => array(
    name      => Doe,
    parents   => array(John, Jane),
    children => array(Paul, Mark, Simone)
  ),
  address => array(
    number    => 34,
    street    => Main Street,
    city      => Nowheretown,
    zipcode   => 12345
  )
);

解析这个YAML将会自动创建下面的PHP数组:

house:
   family:
     name:      Doe
     parents:
       - John
       - Jane
     children:
       - Paul
       - Mark
       - Simone
   address:
     number: 34
     street: Main Street
     city: Nowheretown
     zipcode: 12345

在YAML里面,结构通过缩进来表示,连续的项目通过减号"-"来表示,map结构里面的key/value对用冒号":"来分隔。YAML也有用来描述好几行相同结构的数据的缩写语法,数组用[]包括起来,hash用{}来包括。因此,前面的这个YAML可以缩写成这样:

house:
   family: { name: Doe, parents: [John, Jane], children: [Paul, Mark, Simone] }
   address: { number: 34, street: Main Street, city: Nowheretown, zipcode: 12345 }

YAML是"Yet Another Markup Language(另一种标记语言)"的缩写,读音"yamel",或者"雅梅尔"。这种格式大约是2001年出现的,目前为止已经有多种语言的YAML解析器。

提示 YAML格式的详细规格可以在YAML官方网站http://www.yaml.org/找到。

如你所见,写YAML要比XML快得多(不需要关闭标签或者引号),并且比.ini文件功能更强(ini文件不支持层次)。所以symfony选择YAML作为配置信息的首选格式。在本书你会看到很多YAML文件,不过它很直观你用不着更深入地研究YAML。


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!