使用fwrite()函数的一个问题

0 views
Skip to first unread message

ajax

unread,
Oct 22, 2009, 9:56:49 AM10/22/09
to CPHPUG-中国PHP用户组
源代码如下:
<?php
$tireqty = 100;
$oilqty = 10;
$date = date('H:i, jS F');
@ $fp = fopen("$DOCUMENT_ROOT/../html/test/orders/orders.txt", 'ab');
if(!$fp){
echo "<p><strong>Your order could not processed!</strong></p>";
exit;
}
echo $tireqty.' tires<br />';
echo $oilqty.' bottles of oil<br />';
$outputstring = $date." ".$tireqty." tires ".$oilqty." oil\n";
fwrite($fp, $outputstring, strlen($outputstring));
fclose($fp);
?>
在我对页面刷新了4次后,order.txt按道理来说应该是如下显示的:
13:48, 22nd October 100 tires 10 oil
13:48, 22nd October 100 tires 10 oil
13:49, 22nd October 100 tires 10 oil
13:51, 22nd October 100 tires 10 oil
而事实上它们却没有正常换行,换行符“\n”变成了一块黑糊糊的东西,还望大家帮忙看下啊,谢谢。
PS:我是在XP下运行的。

Zhang Hongyin

unread,
Oct 22, 2009, 9:28:13 PM10/22/09
to cph...@googlegroups.com
\n在记事本里就是那个样子,你用写字板或ue或ep来看就正常了。
\n是unix风格的行结束标记
\r\n才是windows用的行结束标记。
还有个\n\r是mac用的。

2009/10/22 ajax <aja...@gmail.com>

ajax

unread,
Oct 23, 2009, 10:11:08 AM10/23/09
to CPHPUG-中国PHP用户组
呵呵,受教了,谢谢了啊。
Reply all
Reply to author
Forward
0 new messages