带有右侧空格的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). "
";
}
fclose($file);PHP逐行删除右侧空格代码如下:
运行后即可将删除右侧空格后的文件保存到filetmp.txt
补充:
还可以将带有右侧空格的文件在eclipse环境下编辑保存,不需要代码即可自动删除右侧空格。更加方便。