发布于 2015-08-27 16:38:47 | 258 次阅读 | 评论: 0 | 来源: 网络整理
According to the official YAML website, YAML is “a human friendly data serialization standard for all programming languages”.
Even if the YAML format can describe complex nested data structure, this chapter only describes the minimum set of features needed to use YAML as a configuration file format.
YAML is a simple language that describes data. As PHP, it has a syntax for simple types like strings, booleans, floats, or integers. But unlike PHP, it makes a difference between arrays (sequences) and hashes (mappings).
The syntax for scalars is similar to the PHP syntax.
Strings in YAML can be wrapped both in single and double quotes. In some cases, they can also be unquoted:
A string in YAML
'A singled-quoted string in YAML'
"A double-quoted string in YAML"
Quoted styles are useful when a string starts or end with one or more relevant spaces, because unquoted strings are trimmed on both end when parsing their contents. Quotes are required when the string contains special or reserved characters.
When using single-quoted strings, any single quote '
inside its contents
must be doubled to escape it:
'A single quote '' inside a single-quoted string'
Strings containing any of the following characters must be quoted. Although you
can use double quotes, for these characters it is more convenient to use single
quotes, which avoids having to escape any backslash :
:
, {
, }
, [
, ]
, ,
, &
, *
, #
, ?
, |
,
-
, <
, >
, =
, !
, %
, @
, `
The double-quoted style provides a way to express arbitrary strings, by
using to escape characters and sequences. For instance, it is very useful
when you need to embed a
n
or a Unicode character in a string.
"A double-quoted string in YAMLn"
If the string contains any of the following control characters, it must be escaped with double quotes: