I help manage a nonprofit website with a large number of html files, probably around 1,000. Broken links are a hassle, and I was wondering if it would be possible, perhaps with PHP, to create a program that replaces a text string (ie a URL) across all of these files.
Would it create a lot of server strain with this many files?
What about if, say 10 people, were simultaneously using the program to find and replace across all 1,000 files?
It certainly is possible!
The key to this is to be able to read a file in PHP, and to process its contents. Reading is dead-easy, so is writing. Editing is the bit that’ll require your attention.
This snippet of code effectively reads a file, and writes a file. The bit in the middle is where you’ll do your search-and-replace. I strongly recommend using regular expressions for this. preg_replace will come in very handy for this, I am sure. Read up on it, and feel free to edit your question with more details – I’m more than happy to write the regular expressions for you.
Iterating through a directory is also pretty straightforward. You want to open a directory using opendir() and loop through using readdir(), making sure that the return value is not ., .. or false, and is a file.
For your additional question re:multiple users, I’d avoid if I were you. This creates race conditions.