[英]inside the echo, why the php variable can't be printed with html tag
我在表格中打印動態值時遇到問題。 第一張照片是我想要的結果:
<?php
if(in some conditions, the table will appears with dynamic vairalbe) {
//some logic to get the single value, here let's assume the result is 85.00
$single = 85.00;
//here is the table with value
echo '
<table class="table table-striped">
<thead>
<tr>
<th scope="row">Status</th>
<th scope="row">Tax</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Single</th>
<td> {$single} <td>
</tr>
<tr>
</tbody>
</table>
';
}
?>
這里的問題是單引號。 它們幾乎“按原樣”顯示所有內容。 (參考單引號和雙引號的區別)
如果要解析變量,則必須改用雙引號。 ( "
)
重要提示:不要忘記轉義所有其他要在字面上回顯的雙引號。
例子:
<?php
echo "
<table class=\"table table-striped\">
<thead>
<tr>
<th scope=\"row\">Status</th>
<th scope=\"row\">Tax</th>
</tr>
</thead>
<tbody>
<tr>
<th scope=\"row\">Single</th>
<td> {$single} </td>
</tr>
</tbody>
</table>
";
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.