PHP Quick Find Replace Script
I was working on a client who had an older website with about 100 pages and they were all “full html.” By full html I mean the entire layout was stored in every html file, so any change to the layout required a lot of time. So I created a quick and dirty script to load into the directory I was working in, it pulls all files with the defined extension then finds and replaces one string for another.
This script is very easy to setup and run.
Instructions:
- 1. Download script here
(http://www.warnerdata.com/freeDownloads/FindAndReplace.zip) - 2. Unzip and open replace.php in notepad or your choice of editor
- 3. There are three variables that must be defined
a. $ext = “php” – Set this to whatever extension you wish to edit. Currently it is only setup to do one extension at a time. I usually run it on php and then the html files, then css if urls needs to be changed.
b. $current = “123456” – Set this to whatever your pages currently say. This is what you want to replace/get rid of.
c. $new = “ABCD” – Set this to whatever is to replace $current.
d. An example of replacing info@warnerdata.com to support@warnerdata.com would be:
$ext = “html”
$current = “info@warnerdata.com”
$new = “support@warnerdata.com”
- 4. Upload your edited replace.php to whatever directory contains the files you wish to edit
- 5. Point your browser to: http://yoursite.com/directory/replace.php
- 6. Repeat for any other extension
- 7. Delete replace.php
Things that could be added later:
GUI interface with password protection
Do more than one directory at a time
Do more than one file extension at a time
Create backup of files to be edited with an undo button
Hope this helps!
No comments:
Post a Comment