在PHP中使用Heredoc有什么好處?使用赫雷多克在PHP中,您能給出一個示例嗎?
3 回答

飲歌長嘯
TA貢獻1951條經(jīng)驗 獲得超3個贊
$sql = <<<SQLselect * from $tablename where id in [$order_ids_list] and product_name = "widgets"SQL;
$sql = " select * from $tablename where id in [$order_ids_list] and product_name = \"widgets\" ";
$x = "The point of the \"argument" was to illustrate the use of here documents";
$x = <<<EOFThe point of the "argument" was to illustrate the use of here documents EOF;
單株
當(dāng)字符串是常量時使用引號,如 'no variables here'
雙倍
引用時,我可以將字符串放在單行上,并需要變量內(nèi)插或嵌入單引號。 "Today is ${user}'s birthday"
這里
需要格式化和變量內(nèi)插的多行字符串的文檔。

慕神8447489
TA貢獻1780條經(jīng)驗 獲得超1個贊
$html = <<<HTML <div class='something'> <ul class='mylist'> <li>$something</li> <li>$whatever</li> <li>$testing123</li> </ul> </div>HTML;// sometime laterecho $html;
$sql = <<<SQL SELECT * FROM table SQL;
- 3 回答
- 0 關(guān)注
- 837 瀏覽
添加回答
舉報
0/150
提交
取消