search and replace with html files

hi there

I am looking for away of searching from a list of urls and replacing them with a second batch of urls within a collection of html files around 75 html files.(same folder)


so all line by line domains that in the first text file are searched for and replaced by the second line by line domains

first text file could have this
etc etc

there are about 50 urls all within the html files in the first textfile so perfect matches through out.

Then i need to replace those urls within the html with the second text file (line by line)

both files are different in the amount of urls the only thing that is identical are the domain names up until the http://www.domain.whatever/ after that the seconf text file has a different ?=XXXX

Then output the master files into another folder

I dont think this is as stright forward as text to text then master text file

best regards

Who is Participating?
ZylochConnect With a Mentor Commented:

That could be a bit tricky. This example won't allow for Javascript links such as window.location changes but only for <a href>, are you asking for something like this:?

//Set files
$firstFile = "file1.html";
$secondFile = "file2.html";

//Open first file and get contents

//Grab links

//$matches[2] should be the array of links
//Open 2nd file

//Replace all URLs
foreach ($matches[2] as $url) {



This hasn't been error checked yet and might have some errors, but give it a try.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.