本文实例讲述了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($