I have a folder with about 1000 PHP files in it, each file contains a domain name (for instance, example.com) Is there a way to run some type of automated script or something to open and change all the "example.com" to "newdomain.com"? Or, would I have to go file by file. I don't have anything backed up in a database, just the files from the FTP. Please let me know if you have any ideas. Thanks.
I don't see why are those URL's in separate (more than 1000) PHP files but I think you should use preg_replace to change your url's, something like : $url_to_change = 'example.com'; $pattern = '/newdomain.com/'; $replacement = 'example.com'; $new_url = preg_replace($pattern, $replacement, $url_to_change); PHP: I would store the urls in a database and then run the script above in a while loop : $url_to_change = $database_row['urls']; $patterns = array(); $patterns[1] = '/example1.com/'; $patterns[2] = '/example2.com/'; $patterns[3] = '/example3.com/'; $replacements = array(); $replacements[1] = 'newdomain1.com'; $replacements[2] = 'newdomain2.com'; $replacements[3] = 'newdomain3.com'; echo preg_replace($patterns, $replacements, $url_to_change); PHP: I hope you got the idea.
You could also just download Notepad++ and use its seach-replace function. You can "search in data" where you can specify the directory where your 1000 files are, search for "example.com" and replace with "newdomain.com. You can even use regular expressions if needed.
+1 to GMF. Also, PSPad and Eclipse also have this functionality. If your editor does not have similar functionality, I suggest you upgrade. In the future, it is a good idea to either store that domain in a variable, or if it is the current host, to use $_SERVER['HTTP_HOST']