Use this simple code to search and replace text in a local file.
|
1 2 3 4 5 6 7 8 9 10 |
function replace_text_in_file($filename,$oldValue,$newValue) { // read the file $file = file_get_contents($filename); // replace the data $file = str_replace($oldValue, $newValue, $file); // write the file file_put_contents($filename, $file); } |
Make sure you have write permissions for this file.
Usage:
|
1 |
replace_text_in_file(FILENAME,OLD_TEXT,NEW_TEXT); |
Mail List Subscription Form
Please fill in and submit the form below to subscribe to our mailing list.