源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

PHP实现逐行删除文件右侧空格的方法 <font color="red">原创</font>

  • 时间:2020-09-28 15:06 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:PHP实现逐行删除文件右侧空格的方法 <font color="red">原创</font>
本文实例讲述了PHP实现逐行删除文件右侧空格的方法。分享给大家供大家参考,具体如下: 在编辑整理代码的过程中发现网上的一些代码经常会有不少的右侧空格,偶尔会影响到代码的排版与阅读,所以写了一段简单的php代码来逐行删除文件右侧的空格,并保存到新的文件中。 带有右侧空格的demo.txt文件(该文件是PHP逐行读取功能代码)如下:
$file = fopen("welcome.txt", "r") or exit("Unable to open file!"); 
//Output a line of the file until the end is reached 
while(!feof($file)) 
{ 
 echo fgets($file). "<br />"; 
} 
fclose($file); 

PHP逐行删除右侧空格代码如下:
<?php
 $file=@fopen("demo.txt","r") or exit("file don't exit");
 $tmpstr="";
 while(!feof($file)){
 $tmpstr .= rtrim(fgets($file))."\n";
 }
 fclose($file);
 file_put_contents("filetmp.txt",$tmpstr);
?>

运行后即可将删除右侧空格后的文件保存到filetmp.txt [b]补充:[/b] 还可以将带有右侧空格的文件在eclipse环境下编辑保存,不需要代码即可自动删除右侧空格。更加方便。 希望本文所述对大家PHP程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部