[英]If Condition inside php variable
我陷入了一個問題。
我在PHP變量中有HTML元素。 現在,我想在html元素中添加條件。
我的代碼是這樣的。
<?php
$x = 1;
$html =
'<style>
b
{
paading:0;
margin:0;
}
</style>
<table width="790px" style="font-family:Open Sans;">
<!--Want If Condition Here-->
if($x != 1)
{
<tr>
<td colspan="2">
My Separate Portion
</td>
</tr>
}
<strong></strong>
<tr> <td colspan="2"> <hr style="background-color:#E44510; height:10px;"> </td> </tr>';
echo $html;
?>
如果有人可以幫助我,這非常好看。
<?php
$x = 1;
$html =
'<style>
b
{
paading:0;
margin:0;
}
</style>
<table width="790px" style="font-family:Open Sans;">';
if($x != 1)
{
$html .= '<tr>
<td colspan="2">
My Separate Portion
</td>
</tr>';
}
$html .= '<strong></strong>
<tr> <td colspan="2"> <hr style="background-color:#E44510; height:10px;"> </td> </tr>';
echo $html;
?>
否則,您可以輕松地使用它。
<?php
$x = 1;
?>
<style>
b
{
paading:0;
margin:0;
}
</style>
<table width="790px" style="font-family:Open Sans;">
<!--Want If Condition Here-->
<?php
if($x != 1)
{
?>
<tr>
<td colspan="2">
My Separate Portion
</td>
</tr>
<?php
}
?>
<strong></strong>
<tr> <td colspan="2"> <hr style="background-color:#E44510; height:10px;"> </td> </tr>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.