是否有可能并且在php中的if语句中使用heredoc进行编码是否正确?
if($selection!='')
{
$price=getselection($selection,$getprice[$selection]);
if ($selection<8)
{
print 'Please enter the amount<br />';
print '<form action="" method="post"><input type="text" name="money1" value="'.$money1.'">';
print '<input type="text" name="money2" value="'.$money2.'">';
print '<input type="text" name="money3" value="'.$money3.'"><input type="submit">';
print '<input type="hidden" name="selection" value="'.$selection.'"';
print '</form><br>';
if (($money1!='')&&($money2!='')&&($money3!==''))
{
$total=$money1+$money2+$money3;
$money=getmoney($total);
$change=getchange($total,$price);
}
}
}
echo '</pre>';
Run Code Online (Sandbox Code Playgroud)
我试图避免摆脱PHP代码,跳进html然后再回到php,我只是试图保持PHP脚本上的一切; 另外,使用多个打印件是凌乱的,谢谢你没有火红.
像这样?
if (conditional)
{
$foo = <<<html
<tag></tag>
<tag></tag>
<tag></tag>
<tag></tag>
<tag></tag>
html;
}
Run Code Online (Sandbox Code Playgroud)
我不知道heredoc'不会起作用'的任何情况.只需要注意确保heredoc的结束语句没有前导字符.在我的例子中html关闭heredoc并且绝对没有包括空格的主要字符.