问题如题。
最近在学PHP,看到fprintf这里,尝试打印“\n”,怎么样都打不出来(其他内容正常)。请问下,这是什么原因啊?怎么在文件中打印出“\n”呢?谢谢~~附PHP代码:
$outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil\t".$sparkqty." spark plugs\t\$".$totalamount."\t".$address."\n";
// open file for appending
@$fp = fopen("$DOCUMENT_ROOT/flyfy1_data/practice/orders.txt","a+t");
if(!fp)
{
echo "<p><strong>Your order could not be processed at this time.. Please try again later.</strong></p>";
}
echo $outputstring; fwrite($fp,$outputstring,strlen($outputstring)+10);
fprintf($fp,"\n");
最近在学PHP,看到fprintf这里,尝试打印“\n”,怎么样都打不出来(其他内容正常)。请问下,这是什么原因啊?怎么在文件中打印出“\n”呢?谢谢~~附PHP代码:
$outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil\t".$sparkqty." spark plugs\t\$".$totalamount."\t".$address."\n";
// open file for appending
@$fp = fopen("$DOCUMENT_ROOT/flyfy1_data/practice/orders.txt","a+t");
if(!fp)
{
echo "<p><strong>Your order could not be processed at this time.. Please try again later.</strong></p>";
}
echo $outputstring; fwrite($fp,$outputstring,strlen($outputstring)+10);
fprintf($fp,"\n");
windows系统,文本文件的回车是\r\n,linux系统是\r或\r\n
a+t 为什么有个t?
"a+t" : t表示以文本方式打开
恩,谢谢啦~~加上“\r\n”,问题解决;
PS:用notepad++打开用“\n”换行的文件,可以显示换行;但用Windows自带的NotePad不可以。