Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find and Replace

Status
Not open for further replies.

dagger2002

Programmer
Nov 23, 2004
172
US
ok I need to change 4000 file name extensions from .htm to .php on my mac and was looking for a quick way to do it any ideas?

Thanks
 
Why are you asking here? This is not a PHP question.

Why don't you change Apache to send .htm files through PHP and be done with it. As you change files, you can resave them as PHP. Of course you have to make sure references with in the files change also.

Ken
 
I'd use glob() to get the appropriate filenames, preg_replace() to change the old filenames to the new filename, then use rename() to perform the change:

Code:
<?php
foreach (glob('*.htm') as $filename)
{
        $newfilename = preg_replace ('/\.htm$/', '.php', $filename);

        rename ($filename, $newfilename);
}
?>

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
i assume you wish to do this in php? on a pc, of course, it would be a simple xcopy in a dos box. dos mac not have an equivalent?

are you just trying to get php to parse htm files as well as php files? in which case just change the httpd.conf file (if you are using apache) to direct htm files through the php module (assuming you are using php as a mod).

otherwise you need to do some combination of a recursive analysis on a directory contents and the rename() function.
 
I am running a mac not a pc.

I have dreamweaver, BBedit, and GoLive. as html editing programs
 
i dont think anyone was asking about your html editing apps? kerbnsn and i suggested routing htm through php in your web server. very valid too is his point that changing the file extension amy result in broken links.

i guess with the combination of posts you now have all the information you need. post back if you remain stuck.
 
i don't use SSI (through apache) but from what i do know about apache I believe that you do not need to have the file name as .php. if ssi is enabled in your apache config then each file served will be parsed for the relevant variables before output to the browser.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top