查找并替换多个文件 [英] Find and replace in multiple files
本文介绍了查找并替换多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的,最好的php解决方案是搜索一堆文件内容中的某个字符串并将其替换为其他字符串.
OK, whats the best solution in php to search through a bunch of files contents for a certain string and replace it with something else.
完全像notepad ++那样,但是显然我不需要该接口.
Exactly like how notepad++ does it but obviously i dont need the interface to that.
推荐答案
foreach (glob("path/to/files/*.txt") as $filename)
{
$file = file_get_contents($filename);
file_put_contents($filename, preg_replace("/regexhere/","replacement",$file));
}
这篇关于查找并替换多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文