我是靠谱客的博主 沉默云朵,这篇文章主要介绍php nowDoc and HereDoc,现在分享给大家,希望可以做个参考。

<?php
//heredoc 注意 名称之前不能有任何输出 相当于双引号定界符
$id=2;
$username='queen';
$email='123@.qq.com';
$str="<table border='1' width='80%' bgcolor="pink">
<tr>
<td>编号</td>
<td>用户名</td>
<td>邮箱</td>
</tr>
<tr>
<td>1</td>
<td>liuan</td>
<td>13770933782@qq.com</td>
</tr>
<tr>
<td>{$id}</td>
<td>{$username}</td>
<td>{$email}</td>
</tr>
</table>";
echo $str;
//通过heredoc的写法
$str=<<<EOF
this is a test
<h1 align='center'>Hello world<small>power by king </small></h1>
EOF;
echo $str;
//table>tr*2>td{x}*3
$str=<<<TABLE
<table border='1' width='80%' bgcolor="gold">
<tr>
<td>编号</td>
<td>用户名</td>
<td>邮箱</td>
</tr>
<tr>
<td>1</td>
<td>liuan</td>
<td>13770933782@qq.com</td>
</tr>
<tr>
<td>{$id}</td>
<td>{$username}</td>
<td>{$email}</td>
</tr>
</table>
TABLE;
echo $str;
echo "<hr/>";
$str=<<<"test"
<h1>这样写<small>也行</small> </h1>
test;
echo "$str";
echo "<hr/>";
#下面是nowdoc 相当于单引号
#注意,中间不可以有输出
$str=<<<'EOD'
<h1>this is test</h1>
用户名:{$username}
EOD;
echo "$str";

 

最后

以上就是沉默云朵最近收集整理的关于php nowDoc and HereDoc的全部内容,更多相关php内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(135)

评论列表共有 0 条评论

立即
投稿
返回
顶部