如何删除从PHP文件中的一行? [英] How to delete a line from the file with php?

查看:82
本文介绍了如何删除从PHP文件中的一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 $ DIR 和一个名为 $行字符串,我知道这个字符串是该文件的完整产品线,但我不知道它的行号,我想从文件中删除,我该怎么办?

是否可以用awk?


解决方案

  $内容=的file_get_contents($目录);
$内容= str_replace函数($行,'',$内容);
的file_put_contents($目录,$内容);

I have a file named $dir and a string named $line, I know that this string is a complete line of that file but I don't know its line number and I want to remove it from file, what should I do?

Is it possible to use awk?

解决方案

$contents = file_get_contents($dir);
$contents = str_replace($line, '', $contents);
file_put_contents($dir, $contents);

这篇关于如何删除从PHP文件中的一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆