how to add footer to many html files?

Discussion in 'PHP' started by brokensoft, Jan 16, 2007.

  1. #1
    i have more than 3000 html files
    i want to add a footer to all files
    if i edit every file to add
     
    <?
    include"footer.html";
    ?>
    
    Code (markup):
    it will take more than 10 days

    how could i add afooter to all files and in the same time getting title and file name displayed. i mean "without changing files names or titles"
    say if file title is digitalpoint after adding footer the file title will be digitalpoint
    and
    if file name is digitalpoint.html after adding footer the url will be "mysite.com/digitalpoint.html"
     
    brokensoft, Jan 16, 2007 IP
  2. solidphp

    solidphp Peon

    Messages:
    46
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Are you on Linux or Windows? This would be simple using Linux shell scripting.
     
    solidphp, Jan 16, 2007 IP
  3. brokensoft

    brokensoft Active Member

    Messages:
    214
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #3
    iam on Linux server
     
    brokensoft, Jan 16, 2007 IP
  4. solidphp

    solidphp Peon

    Messages:
    46
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ok, make sure you create backups before you do this. Don't do this unless you feel comfortable doing it and have an understanding of the command line!!!! I've not tested this, but it should work.

    1. create a temp directory:

    mkdir temp_directory;
    PHP:
    2. move to the temp_directory:

    cd temp_directory;
    PHP:
    3. copy your files to this directory for the edits:

    cp -R /path/to/live/files .;
    PHP:
    4. append the php include to each file in the directory:

    for x in `ls`; do echo "<?PHP include 'footer.html'; ?>" >> $x; done;
    PHP:
    5. copy the files over to production:

    cp -fr * /path/to/live/files;
    PHP:
    That should at least add the footer to each file. I didn't understand the second part of what you are trying to do.

    There might be an easier way to append the code to each file, but this is how I would do it I think.
     
    solidphp, Jan 16, 2007 IP
  5. dshah

    dshah Well-Known Member

    Messages:
    1,840
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    115
    #5
    you can use any find-replace tool to replace </html> (the end tag for all your html files) with include + </html>.

    If you want I can program this for you in Java and run it over all your files for 5$ :)
     
    dshah, Jan 16, 2007 IP
  6. solidphp

    solidphp Peon

    Messages:
    46
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    3K files is too many to open in a text editor. He's using Linux so the commands I posted should do the job completely in just a few seconds. The command line is very powerful, no need to write java code.
     
    solidphp, Jan 16, 2007 IP
  7. brokensoft

    brokensoft Active Member

    Messages:
    214
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #7
    thanks solidphp but my webhost prevent me from making any commands
    could you give me another way
    i understand some steps :
    making temp_directory folder and uploading the files to it.
    what is next ?

    thanks again
     
    brokensoft, Jan 16, 2007 IP
  8. solidphp

    solidphp Peon

    Messages:
    46
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Look at my signature if you want a tolerant host. I work with people in a one on one basis and can help with situations like this.

    Anyway, without that kind of access on the server level. I would suggest doing your work offline on a local PC. Maybe download a bootable CD here:

    http://www.ubuntu.com/products/GetUbuntu/download?action=show&redirect=download

    You can download that, burn it to CD, keep it in your drive and reboot your PC. You can then FTP in the 3K files, make the changes locally and then FTP the files back.

    Sounds like a big hassle, but I don't think there's an "quick/easy" solution with the amount of data at hand. Let me know if I can help.
     
    solidphp, Jan 16, 2007 IP
  9. sukantab

    sukantab Well-Known Member

    Messages:
    2,075
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    110
    #9
    Install Textpad and write an easy macro to do this. Then Open 200 files(drag-drop ) at a time(to be safe of not hanging the PC) run the macro to change it.
    Then save all and upload.

    Let me know, if you need help in this.
     
    sukantab, Jan 17, 2007 IP
  10. rays

    rays Active Member

    Messages:
    563
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #10
    If you have a windows system, you can try with dreamweaver where you have an option for find and replace in entire directory...

    I am not sure what will heppen when you try with 3K files at a time but it works for me when i am editing some 100's at a time...

    cheers mate
     
    rays, Jan 17, 2007 IP
  11. brokensoft

    brokensoft Active Member

    Messages:
    214
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #11
    is there any option in dreamweaver or any another programme that enable me to search for a word or tag "</body>" and add after it my wanted code.

    <?
    include"footer.html";
    ?>
    Code (markup):
    i mean - programme that have option "find in files source code and add after"
     
    brokensoft, Jan 17, 2007 IP
  12. carl_in_florida

    carl_in_florida Active Member

    Messages:
    1,066
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    90
    #12
    That's what he was telling you in the post above. Do a find and replace.

    find </body>

    and replace it with "your footer info" </body>
     
    carl_in_florida, Jan 17, 2007 IP
  13. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #13
    I doubt there's an "add after" feature in any editor but you achieve the same thing with find/replace. Find "</body>" replace with "<?php include 'footer.html'; ?></body>"

    You could do this with mod_rewrite and a php script - it wouldn't actually edit the files but it would have the same effect.
    RewriteCond %{REQUEST_URI} -f
    RewriteRule (*.)\.html index.php?file=$1 [NC,L]
    Code (markup):
    Intercept every request, check the file exists and rewrite to the index.php script:
    <?php
    include $_GET['file'];
    include 'footer.html';
    ?>
    PHP:
    Obviously it'd be a bit better written than that but you get the idea.
     
    rodney88, Jan 17, 2007 IP
  14. rays

    rays Active Member

    Messages:
    563
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #14
    just open any file in a folder press ctrl+f (control and f key) .. you will get a window .. in search text box add

    </body>

    and in replacement text add

    <? include ("footer.html") ?>
    </body>


    then on top of that windown (left side) you will find a drop down with some options like CURRENT DOCUMENT, ALL OPEN FIELS ...etc Select option of FOLDER ...

    and then simple click on replace all (on top tight side)


    I hope i have cleared all of your doubts..




     
    rays, Jan 17, 2007 IP