PHP中的多行字符串如何表达比较好?
How the expression of multiline string in PHP is better?
如果我想说
Hello
World
,建议使用 '
(撇号)或 "
(引号)?
示例:
<?php
$apostrophe = 'Hello' . "\n" . 'World!';
$quotation_mark = "Hello\nWorld!";
$newline = 'Hello
World!';
echo (($apostrophe == $quotation_mark) && ($apostrophe == $newline));
输出:1
(真)
你怎么看这个
$text = 'Hello' . PHP_EOL
. 'World!';
在我看来这很好读
引号之间的区别很容易。带有双引号的 String 会被解析为变量和特殊值,另一个则不会。
如果我想说
Hello
World
,建议使用 '
(撇号)或 "
(引号)?
示例:
<?php
$apostrophe = 'Hello' . "\n" . 'World!';
$quotation_mark = "Hello\nWorld!";
$newline = 'Hello
World!';
echo (($apostrophe == $quotation_mark) && ($apostrophe == $newline));
输出:1
(真)
你怎么看这个
$text = 'Hello' . PHP_EOL
. 'World!';
在我看来这很好读 引号之间的区别很容易。带有双引号的 String 会被解析为变量和特殊值,另一个则不会。