Re: [請益] 讀檔去除空白及連續空白

看板PHP作者 (本機端)時間9年前 (2015/01/22 11:57), 編輯推噓4(401)
留言5則, 5人參與, 最新討論串2/2 (看更多)
$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
為什麼你的ip不是127.0.0.1
01/22 12:10, 1F

01/22 12:43, , 2F
推id
01/22 12:43, 2F

01/23 10:55, , 3F
請問本機,掃帚在哪?
01/23 10:55, 3F

01/23 20:49, , 4F
這id XDDDDDD 帥到炸
01/23 20:49, 4F

01/24 19:15, , 5F
謝謝幫助^^,已解決
01/24 19:15, 5F
文章代碼(AID): #1Km7L0tQ (PHP)
文章代碼(AID): #1Km7L0tQ (PHP)