Jump to content

Php open file


shage

Recommended Posts

Im trying to open a list of htm files, on those files find the </body> tag so i can add a include to all the files to call a footer so i dont have to change copywrite on all the pages but only have to change one, i didnt think about this long before, so now i have thousands of files that still say 1995 on the bottom of them thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/88621-php-open-file/
Share on other sites

Even using that wont remove the 1995 from current pages.

 

either, use a text editor that can do a search & replace over multiple files (UltraEdit is what I use)

or create a script to make these changes for u.

 

this can be done with php, and if the dates are in the same format, a preg_match/replace function to add in the new custom footer/code.

 

if ya need it done today, go with option 1

if it can wait a couple of days, consider option 2 (then u have a new tool in yer box)

Link to comment
https://forums.phpfreaks.com/topic/88621-php-open-file/#findComment-453787
Share on other sites

this might* work if you do it proper  actually it won't work properly, but i'll get you going and you can figure out out the reset that is

If you want to use a php include you will need to force your server to phrase html extensions (or .htm) as php files.

 

Also your files in the array must have a proper absolute internal address or a proper relative adderss to this scripts location

<?php
$files = array("file1.html","myfavs.htm","index.html");
$insert_line = "<p>Copyright © 2008</p>";
foreach($files as $value){
$temp_file = file_get_contents($files);
#Here you will need to explode apart said file so the positioning is right I will psedo this
$file_top = "TEMP FILE TOP PART";
$file_bottom = "TEMP FILE BOTTOM PART";
file_put_contents($value,$file_top.$insert_line.$file_bottom);
unset($temp_file);
}
?>

 

So you will need to figure out how to break apart the files (using regex or something similar) and then from there put the new line in its "sandwich"

Link to comment
https://forums.phpfreaks.com/topic/88621-php-open-file/#findComment-453880
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.