help-add content to all pages at once

andhrafun

New Member
Messages
3
Reaction score
0
Points
0
sir, i have made nearly some 200 html pages and uploaded them.i want to add some common text to all the pages instead of editing each and every page which will take very much time . for example ,i want to add the below one :
"welcome everybody, this is my new site , i am bhaskar "
can i add the above line to all of my pages in a folder at once , PLEASE HELP ME REGARDING THIS ...
also....i forgot to add keywords to all the pages ....please tell me how to add the keywords to all pages ...
also please tell me whether the STAFF of this website will be replying or not ....
THANKING YOU .....
 

taekwondokid42

New Member
Messages
268
Reaction score
0
Points
0
This is a php script, but php and html go together really well.

http://www.tizag.com/phpT/include.php

If that is somewhat confusing, you can start at the introduction of php and keep going until you get to this point.

I find tizag a great tutorial overall, so you can use that for anything you might have questions about.
 

Pingy

New Member
Messages
46
Reaction score
0
Points
0
I believe I can be of some assistance here. Now, I'm taking this as a need to include the same text on almost 200 HTML pages without going in and doing it by hand. Much like taekwondokid42 suggested, this is where we cue PHP.

In a new file ('mass_edit.php' -- just a suggestion for the name, though):
PHP:
<?
$directory = 'data'; // THE NAME OF THE FOLDER THAT CONTAINS ALL OF THOSE PAGES GOES HERE
$dir_hand = opendir($directory); // CREATE DIRECTORY HANDLE
while (($file = readdir($dir_hand)) !== false) // LOOP THROUGH ALL FILES
 {
$ext = substr($file, strpos($file, '.') + 1, strlen($file) - strpos($file, '.') - 1); // DETERMINE EXTENSION
$valid_ext = array('php', 'html', 'shtml', 'htm'); // DECLARE EXTENSIONS THAT SHOULD BE MODIFIED
if (in_array($ext, $valid_ext)) // TEST IF EXTENSION IS VALID
 {
$old_data = file_get_contents($directory . '/' . $file); // OLD DATA OF THE FILE
$file_hand = fopen($directory . '/' . $file, 'w'); // CREATE FILE HANDLE
fwrite($file_hand, file_get_contents('to_include.php') . $old_data); // PLACE CONTENTS OF "to_include.php" AT THE BEGINNING
 }
 }
?>

Then, just throw the HTML that you'd like to be placed at the beginning of each page in a new file called to_include.php and run mass_edit.php. Remember, though, that this script is going to take all of the contents of that file and throw it at the very beginning of every single valid (extension-wise) file in the folder you specify.

Because I don't know how your HTML pages are structured, I couldn't do anything else with this. If, however, you'd like to send me the source code of one of those pages, I can modify this so that it better suits your needs. Hope I've helped...
 
Last edited:

andhrafun

New Member
Messages
3
Reaction score
0
Points
0
thanks for the help, after completing my work, i will give the source code
 
Top