初始化字符串主要有兩種方式:
$myString = 'my text';
$myOutput = "$myString more text.";
單引號和雙引號的區(qū)別在于單引號不發(fā)生interpolation,而雙引號則需要:
$myOutput = '$myString more text.' 將輸出: $myString more text.
$myOutput = “$myString more text.” 將輸出 :my text more text.
字符串可以使用‘.’來做鏈接操作:
$CombinedString = 'my text' 等價于 $CombinedString = 'my'.'text'
還有一種創(chuàng)建多行字符串的方法,稱為heredoc
echo <<<
line one
line two
line three
theEnd
<<<后接定義的結(jié)束標(biāo)記,在輸入完內(nèi)容后接結(jié)束標(biāo)記,需要留心結(jié)束標(biāo)記不能出現(xiàn)在文本內(nèi)容中,否則會導(dǎo)致系統(tǒng)語法匹配第一個結(jié)束位置。以上的例子創(chuàng)建了一個三行字符串。