如何在HTML表的TD元素中使用echo?

时间:2018-03-17 13:02:05

标签: php html

这是图片:

tax invoice

我必须在HTML表的td元素中使用echo。当我尝试这个时,它显示一个尖括号错误。我该如何避免这个错误?以下是我的代码。

<tr>
      <td>Net Amount</td>
      <td><b>'.$order_data['net_amount'].'</b></td>
  </tr>
  <tr>
   $number = $order_data['net_amount'];
   $no = round($number);
   $point = round($number - $no, 2) * 100;
   $hundred = null;
   $digits_1 = strlen($no);
   $i = 0;
   $str = array();
   $words = array('0' => '', '1' => 'One', '2' => 'Two',
    '3' => 'Three', '4' => 'Four', '5' => 'Five', '6' => 'Six',
    '7' => 'Seven', '8' => 'Eight', '9' => 'Nine',
    '10' => 'Ten', '11' => 'Eleven', '12' => 'Twelve','13' => 'Thirteen',
    '14' => 'Fourteen', '15' => 'Fifteen', '16' => 'Sixteen',
    '17' => 'Seventeen','18' => 'Eighteen', '19' =>'Nineteen', 
    '20' => 'Twenty','30' => 'Thirty', '40' => 'Forty', 
    '50' => 'Fifty','60' => 'Sixty', '70' => 'Seventy',
    '80' => 'Eighty', '90' => 'Ninety');
   $digits = array('', 'Hundred', 'Thousand', 'Lakh', 'Crore');
   while ($i < $digits_1) {
     $divider = ($i == 2) ? 10 : 100;
     $number = floor($no % $divider);
     $no = floor($no / $divider);
     $i += ($divider == 10) ? 1 : 2;
     if ($number) {
        $plural = (($counter = count($str)) && $number > 9) ? 's' : null;
        $hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
        $str [] = ($number < 21) ? $words[$number] .
            " " . $digits[$counter] . $plural . " " . $hundred
            :
            $words[floor($number / 10) * 10]
            . " " . $words[$number % 10] . " "
            . $digits[$counter] . $plural . " " . $hundred;
     } else $str[] = null;
  }
  $str = array_reverse($str);
  $result = implode('', $str);
  $points = ($point) ?
    "." . $words[$point / 10] . " " . 
          $words[$point = $point % 10] : '';
    echo '<td colspan="7"> INR '.$result.' '.$points.'Only</td>';
  </tr>

3 个答案:

答案 0 :(得分:0)

错误来自PHP尝试将<td解析为语句。

您不能将简单的HTML与PHP混合使用。您可以将HTML包装在echoprint语句中,也可以结束PHP标记并重新启动它:

方法1:

    $words[$point = $point % 10] : '';
echo '<td colspan="7"> ...';
echo "INR " .$result. $points ."Only";
echo '</td>';

方法2:

    $words[$point = $point % 10] : '';
?>
<td colspan="7"> ...
    <?php echo "INR " .$result. $points ."Only"; ?>
</td>

答案 1 :(得分:0)

最好的方法是回应`。

所以对于你的代码,这样的东西会起作用:

<?php
    echo '<td colspan="7"> INR '.$result.' '.$points.'Only</td>';
?>

答案 2 :(得分:0)

只需在任何地方启动php编码

<tr>
  <td>Net Amount</td>
  <td><b><?php echo $order_data['net_amount']?></b></td>
</tr>

短手代码可以是,

<tr>
  <td>Net Amount</td>
  <td><b><?=$order_data['net_amount']?></b></td>
</tr>
相关问题