Aus*_*tin 0 html php html-table echo
所以我只是通过PHP语句构建了一个表,但我不确定如何添加一个border="1"属性,因为这会弄乱echo语句并导致编译错误.
这是我的代码,是的,它在这种格式下看起来很可怕,但我只需要以border某种方式为表格提供标签.
echo
"<table><tr>
<th></th>
<th>A</th>
<th>B</th>
<th>AB</th>
<th>O</th>
</tr><tr>
<th>N</th>
<th>" . $ATypeN . "</th>
<th>" . $BTypeN . "</th>
<th>" . $ABTypeN . "</th>
<th>" . $OTypeN . "</th>
<th>".
"</tr><tr>
<th>Y</th>
<th>" . $ATypeY . "</th>
<th>" . $BTypeY . "</th>
<th>" . $ABTypeY . "</th>
<th>" . $OTypeY . "</th>
</tr>
</table>";
Run Code Online (Sandbox Code Playgroud)
您需要在引号字符之前使用(反斜杠)转义引号\,例如:
echo "<table border=\"0\"><tr>";
Run Code Online (Sandbox Code Playgroud)
您也可以在双引号内使用单引号,反之亦然,例如:
echo '<table border="0"><tr>';
Run Code Online (Sandbox Code Playgroud)
要么:
echo "<table border='0'><tr>";
Run Code Online (Sandbox Code Playgroud)
评论者指出了HEREDOC方法,这对您来说也很有价值.以相同的标识符开头和结尾:
/* start with "EOT", must also terminate with "EOT" followed by a semicolon */
echo <<<EOT
<table><tr>
<th></th>
<th>A</th>
<th>B</th>
<th>AB</th>
<th>O</th>
</tr><tr>
<th>N</th>
<th>$ATypeN</th>
<th>$BTypeN</th>
<th>$ABTypeN</th>
<th>$OTypeN</th>
</tr><tr>
<th>Y</th>
<th>$ATypeY</th>
<th>$BTypeY</th>
<th>$ABTypeY</th>
<th>$OTypeY</th>
</tr>
</table>
EOT; /* terminated here, cannot be indented, line must contain only EOT; */
Run Code Online (Sandbox Code Playgroud)