作者localhost (本机端)
看板PHP
标题Re: [请益] 读档去除空白及连续空白
时间Thu Jan 22 11:57:49 2015
$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://webptt.com/cn.aspx?n=bbs/PHP/M.1421899072.A.DDA.html
1F:推 powyo: 为什麽你的ip不是127.0.0.1 01/22 12:10
2F:推 onininon: 推id 01/22 12:43
3F:推 KawasumiMai: 请问本机,扫帚在哪? 01/23 10:55
4F:推 ProfessUX: 这id XDDDDDD 帅到炸 01/23 20:49
5F:→ xx250919: 谢谢帮助^^,已解决 01/24 19:15