🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] * * * * * ### 一. 字符串的定义方式 * 单引号, 双引号, heredoc 和 newdoc; ### 二. 区别 * 单引号不能解析变量; * 单引号不能解析转义字符, 只能解析单引号和反斜线本身; * 变量和变量, 变量和字符串, 字符串和字符串之间可以用 **.** 连接; * * 双引号可以解析变量, 变量可以用特殊字符和 { } 包含; * 双引号可以解析所有的转义字符; * 也可以用 **.** 连接; * * 单引号效率更高 ### 三. Heredoc 结构的字符串示例 ~~~ echo <<<EOT My name is "$name". I am printing some $foo->foo. Now, I am printing some {$foo->bar[1]}. This should print a capital 'A': \x41 EOT; // 打印结果 My name is "MyName". I am printing some Foo. Now, I am printing some Bar2. This should print a capital 'A': A ~~~ ### 四. Nowdoc 结构字符串示例 ~~~ // 打印结果 My name is "$name". I am printing some $foo->foo. Now, I am printing some {$foo->bar[1]}. This should not print a capital 'A': \x41 ~~~