shage Posted January 30, 2008 Share Posted January 30, 2008 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 More sharing options...
irvieto Posted January 30, 2008 Share Posted January 30, 2008 Use server side includes, or a external javascript file to automatically post your footer on all your web pages. Link to comment https://forums.phpfreaks.com/topic/88621-php-open-file/#findComment-453782 Share on other sites More sharing options...
laffin Posted January 30, 2008 Share Posted January 30, 2008 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 More sharing options...
resago Posted January 30, 2008 Share Posted January 30, 2008 I could write one for you. Link to comment https://forums.phpfreaks.com/topic/88621-php-open-file/#findComment-453873 Share on other sites More sharing options...
cooldude832 Posted January 30, 2008 Share Posted January 30, 2008 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 More sharing options...
resago Posted January 30, 2008 Share Posted January 30, 2008 glob *.htm foreach file{ get_file_contents() string_replace 1995 with <?include ('footer.php')?> put_file_contents() } let me know if you need more complete code. Link to comment https://forums.phpfreaks.com/topic/88621-php-open-file/#findComment-453894 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.