在PHP中使用Heredoc有什么好处?使用赫雷多克在PHP中,您能给出一个示例吗?
3 回答
![?](http://img1.sycdn.imooc.com/5333a1d100010c2602000200-100-100.jpg)
饮歌长啸
TA贡献1951条经验 获得超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;
单株
当字符串是常量时使用引号,如 'no variables here'
双倍
引用时,我可以将字符串放在单行上,并需要变量内插或嵌入单引号。 "Today is ${user}'s birthday"
这里
需要格式化和变量内插的多行字符串的文档。
![?](http://img1.sycdn.imooc.com/545861c80001141e02200220-100-100.jpg)
慕神8447489
TA贡献1780条经验 获得超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 关注
- 814 浏览
添加回答
举报
0/150
提交
取消