1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to Change tons of .HTML Files to .PHP Files Easily?

Discussion in 'Programming' started by Pronet Hosting, Sep 28, 2009.

  1. #1
    How to Change tons of .HTML Files to .PHP Files Easily? Please help :rolleyes:
     
    Pronet Hosting, Sep 28, 2009 IP
  2. Martinoes

    Martinoes Peon

    Messages:
    110
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You just want to change the extension of these files ?
     
    Martinoes, Sep 28, 2009 IP
  3. Pronet Hosting

    Pronet Hosting Active Member

    Messages:
    301
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Yes, just the extensions, I need to change 100,000 files and I don't want to change it one by one :(

     
    Pronet Hosting, Sep 28, 2009 IP
  4. Martinoes

    Martinoes Peon

    Messages:
    110
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If all your files are in the same directory than you can check out this code:

    <?php
    
    $path = "."; 
    if ($handle = opendir($path)) {
        while (false !== ($file = readdir($handle))) {
        	$extension = end(explode(".", $file));
        	$name = explode(".", $file);
        	
        	if ($extension == "html") {
        		rename($path."\\".$file, $path."\\".$name[0].'.php'); 
        		echo "$file\n";
        	}
        }
    
        closedir($handle);
    }
    ?>
    PHP:
     
    Martinoes, Sep 28, 2009 IP
  5. Martinoes

    Martinoes Peon

    Messages:
    110
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Martinoes, Sep 28, 2009 IP
  6. Pronet Hosting

    Pronet Hosting Active Member

    Messages:
    301
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #6
    How can I use this codes? I've copied all the codes and then save as a .php file, what's next? :D

     
    Pronet Hosting, Sep 28, 2009 IP
  7. Pronet Hosting

    Pronet Hosting Active Member

    Messages:
    301
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #7
    Pronet Hosting, Sep 28, 2009 IP
  8. dddougal

    dddougal Well-Known Member

    Messages:
    676
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    108
    #8
    Just upload the file into the directory where all these files are that you want to change and then run that script.

    You may get issues with security. If it throws up an error then you will need to change the permissions on the files and folder.
     
    dddougal, Sep 28, 2009 IP
    Pronet Hosting likes this.
  9. Pronet Hosting

    Pronet Hosting Active Member

    Messages:
    301
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #9
    Thank you so much, reputation added :)

     
    Pronet Hosting, Sep 28, 2009 IP