Re: [請益] 讀檔去除空白及連續空白
$file = fopen("test.txt", "r"); //讀入
$file_w=fopen('output.txt', 'w');//寫入
while(! feof($file))
{
$a = str_replace(' ', '',trim(fgets($file))."\n");
fwrite($file_w ,$a);
}
fclose($file);
fclose($file_w);
若是要寫入同檔案 就必須先把內容讀完在寫入 不然沒辦法
順序要改成下面這樣
$file = fopen("test.txt", "r");
while(! feof($file))
{
$a .= str_replace(' ', '',trim(fgets($file))."\n");
}
fclose($file);
$file_w=fopen('test.txt', 'w');
fwrite($file_w ,$a);
fclose($file_w);
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 210.62.185.25
※ 文章網址: https://www.ptt.cc/bbs/PHP/M.1421899072.A.DDA.html
推
01/22 12:10, , 1F
01/22 12:10, 1F
推
01/22 12:43, , 2F
01/22 12:43, 2F
推
01/23 10:55, , 3F
01/23 10:55, 3F
推
01/23 20:49, , 4F
01/23 20:49, 4F
→
01/24 19:15, , 5F
01/24 19:15, 5F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
請益
2
10