Reputation: 35
I want to edit 100 php files in different folders using php. I have searched on google but doesn't get any help. I want to replace some text with other text on every file. Tell me a suitable way to do it using php.
For eg. I have two texts t1 ,t2 and i want to replace it with v1,v2 in every file how to do it?.
Upvotes: 0
Views: 632
Reputation: 799
for
loop and performing the str_replace()
on each file. I recommend not just doing this blindly as it could be very destructive if you make a mistake.If you've tried this and have a specific problem, come back and post that along with what you've tried!
Upvotes: 1
Reputation: 1795
$files = array(
'directory/file1.php',
'directory/file2.php'
)
$t1 = 'your text 1';
$t2 = 'your text 2';
$t1 = 'your version 1';
$t2 = 'your version 2';
foreach($files as $f) {
$old_content = file_get_contents($f);
$new_content = str_replace($t1, $v1, $old_content);
$new_content = str_replace($t2, $v2, $new_content);
file_put_contents($f, $new_content);
}
Upvotes: 0