JBTALKS.CC

标题: PHP fwrite 的问题。 [打印本页]

作者: 宅男-兜着走    时间: 2009-7-29 09:59 PM
标题: PHP fwrite 的问题。
<?PHP

$file_handle = fopen("title.txt", 'rb');

while (!feof($file_handle) ) {
$line_of_text = fgets($file_handle);
$stringData.= $line_of_text . "\n";
}
$stringData.= "new text document" . "\n";

fclose($file_handle);

$file_handle = fopen("title.txt" , 'w');

if (fwrite($file_handle, $stringData)){
echo "insert successfully";
}
else{
echo "not insert";
}
fclose($file_handle);

?>
为什么 output 是

new text documentnew text document
连在一起的, 但是读出来的时候却可以有 new text document
new text document 分开的呢?
作者: Super-Tomato    时间: 2009-7-29 11:21 PM
原帖由 宅男-兜着走 于 2009-7-29 09:59 PM 发表

<?PHP

$file_handle = fopen("title.txt", 'rb');

while (!feof($file_handle) ) {
$line_of_text = fgets($file_handle);
$stringData.= $line_of_text . "\n";
}
$stringData.= "new text document" . "\n";

fclose($file_handle);

$file_handle = fopen("title.txt" , 'w');

if (fwrite($file_handle, $stringData)){
echo "insert successfully";
}
else{
echo "not insert";
}
fclose($file_handle);

?>
为什么 output 是

new text documentnew text document
连在一起的, 但是读出来的时候却可以有 new text document
new text document 分开的呢?



1. 不明白你所指的 output 是哪部分??
2. 讀取時候又是在哪??
3. $stringData.= $line_of_text . "\n"; 沒必要加上 newline, 這是多餘的




欢迎光临 JBTALKS.CC (https://mobile.jbtalks.cc/) Powered by Discuz! X2.5