简体   繁体   中英

If Condition inside php variable

I am stuck with a problem.

I have HTML element inside PHP variable. Now i want if condition inside html elements.

My code is like this.

    <?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;
    ?>

If anyone can help me out, its very appericiable.

 <?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;
    ?>

OR else you can use this in easy way..

<?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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM