Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find and replace in multiple files

Tags:

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.

Exactly like how notepad++ does it but obviously i dont need the interface to that.

like image 498
David Avatar asked Oct 20 '10 23:10

David


1 Answers

foreach (glob("path/to/files/*.txt") as $filename)
{
    $file = file_get_contents($filename);
    file_put_contents($filename, preg_replace("/regexhere/","replacement",$file));
}
like image 69
Byron Whitlock Avatar answered Sep 23 '22 17:09

Byron Whitlock