drll42469 2017-06-01 08:26
浏览 105

PHP - 打印对齐 - 从文本文件到收据打印机

I am creating a text file with the following code:

$textcreate = "**************************************
" . PHP_EOL;            
$textcreate .= "Item             Amt     Qty     Total" . "
" . PHP_EOL;
if (isset($print_table_for_txt_file["ordereditems"])) {
    foreach ($print_table_for_txt_file["ordereditems"] as $key => $value) {
         $textcreate .= $value['item_name'] . " " . number_format((float) $value['withoutTax_itemPrice'], 2, '.', '')  . "
" . PHP_EOL;
    }
}
$textcreate .= "**************************************
" . PHP_EOL;
$textcreate .= "Amount Payable:             " . round($print_table_for_txt_file['api']['0']['GrandTotal']) . ".00
" . PHP_EOL;
$textcreate .= "**************************************
" . PHP_EOL;

$myfile = fopen("example.txt", "w") or die("Unable to open file!");
fwrite($myfile, $textcreate);

The output of the file is :

************************************** Item Amt Qty Total pen 10.00 1 10.00 ************************************** Amount Payable: 10.00 **************************************

But I want the output to be :

************************************** 
Item             Amt     Qty     Total   
pen             10.00     1      10.00
************************************** 
Amount Payable:                  10.00 
**************************************

What should I do

  • 写回答

1条回答 默认 最新

  • doubo4336 2017-06-01 08:35
    关注

    Browser shrinks all consecutive whitespaces (including and ) in HTML into a single space. You can:

    • use header('Content-Type: text/plain') to make the browser treat the output as plain text (leaving all whitespaces as they are)
    • use the <pre> HTML tag to achieve the same in HTML
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大