我正在创建一个包含以下代码的文本文件:
$textcreate = "**************************************\r\n" . PHP_EOL;
$textcreate .= "Item Amt Qty Total" . "\r\n" . 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, '.', '') . "\r\n" . PHP_EOL;
}
}
$textcreate .= "**************************************\r\n" . PHP_EOL;
$textcreate .= "Amount Payable: " . round($print_table_for_txt_file['api']['0']['GrandTotal']) . ".00\r\n" . PHP_EOL;
$textcreate .= "**************************************\r\n" . PHP_EOL;
$myfile = fopen("example.txt", "w") or die("Unable to open file!");
fwrite($myfile, $textcreate);
文件的输出是:
**************************************项目数量总笔数10.00 1 10.00 * *************************************应付金额:10.00 ********* *********
但我希望输出为:
**************************************
Item Amt Qty Total
pen 10.00 1 10.00
**************************************
Amount Payable: 10.00
**************************************
我该怎么办
答案 0 :(得分:3)
浏览器将HTML中的所有连续空格(包括\r
和\n
)缩小为单个空格。你可以:
header('Content-Type: text/plain')
使浏览器将输出视为纯文本(将所有空格保留原样)<pre>
HTML标记在HTML