您在字符串和字符串中混合了转义引号。这是一个普通的字符串:
$pageTitle = "A string";
如果您希望您的字符串包含引号,则需要使用\
如下方式对它们进行转义:
$pageTitle = "I like the band \"U2\" very much!";
请注意,在 PHP 中,您可以将双引号更改为单引号。以下四种说法是有效的:
$pageTitle = 'I like the band "U2" very much!';
$pageTitle = 'I like the band \'U2\' very much!';
$pageTitle = "I like the band 'U2' very much!";
$pageTitle = "I like the band \"U2\" very much!";
请注意引号需要如何转义!
不同之处在于,当字符串以双引号开头时,会计算内联变量,而单引号则不是这样:
$bandName = "U2";
$pageTitle1 = 'I like the band $bandName very much!';
$pageTitle2 = "I like the band $bandName very much!";
echo $pageTitle1 . "<br />";
echo $pageTitle2;
这个的输出将是
I like the band $bandName very much!
I like the band U2 very much!