加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 在多个文件中查找和替换

发布时间:2020-12-13 18:25:10 所属栏目:PHP教程 来源:网络整理
导读:好吧,最好的解决方案是在php中搜索一堆文件内容以获取某个字符串并将其替换为其他内容. 完全像记事本如何做,但显然我不需要接口. foreach (glob("path/to/files/*.txt") as $filename){ $file = file_get_contents($filename); file_put_contents($filename,
好吧,最好的解决方案是在php中搜索一堆文件内容以获取某个字符串并将其替换为其他内容.

完全像记事本如何做,但显然我不需要接口.

foreach (glob("path/to/files/*.txt") as $filename)
{
    $file = file_get_contents($filename);
    file_put_contents($filename,preg_replace("/regexhere/","replacement",$file));
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读