[英]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.