Question:
replace text in many html files?
flurdled
2012-01-17 08:41:06 UTC
There are three lines of identical code in many html pages on our website. I want to systematically change those three lines to three different lines. Each page would get the exact same treatment.

Is there a quick way to do this, short of manually editing each file?

For what it's worth, we are hosted at bluehost -- I guess I'm hoping there's a way within cpanel to accomplish this.

Thanks
Five answers:
tiger2380
2012-01-17 09:28:32 UTC
Here is a nice little PHP script I just made and it will change certain text to what you want. It will work on multiple files. All the file must be in the same directory and the text what you want to change must be the same. Also, please make a back up first. To use it: create a new text file in the same directory and name it to change.php. Paste the code below into that new text file. Change: index.php, file1.php, etc... to the files you want to change, included the single quote. Replace the text you want to change to between the %% in preg_replace() and the text you want to change from in the other side. Just run this script by going to your website and type in, for example: www.yousite.com/change.php.




$files = array('index.php', 'file1.php', 'file2.php'); //files to change

$count = count($files);

$newfiles = array_map('change', $files);



for($i = 0; $i <= $count; $i++){

$putnew = file_put_contents($files[$i], $newfiles[$i]);

}



function change($file){

$open = file_get_contents($file);

$replace = preg_replace("%-text what you want to change to-%iS", "-texts what you want to change from-", $open);

return $replace;

}



?>
2012-01-17 08:49:49 UTC
Unfortunately there isnt a way to edit those three lines in every page simply. The easiest way to fix this, and is tranfser your html files into a php and using the php function require() or include() to create a template. Heres an example










require("header.html");



?>



Content goes here





morano
2016-12-10 10:58:38 UTC
in case you employ serverside scripting including Hypertext Preprocessor then you definately can. yet differently to incorporate txt documents is to call it using a javascript - like: positioned this interior the physique of your html:
Loading...