Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting same line of text of every web page - "link" insert? 1

Status
Not open for further replies.

pendle666

Technical User
Jan 30, 2003
295
GB
Hello

I've a copyright sentence which goes at the bottom of every web page - unfortunately there are over 5000 of these pages (all transcripts of old documents).

Is there a HTML tag which might "import" this line? They are static HTML pages, but I would like to update one file with the updated year and wording rather than doing it on all the pages manually.

I don't see anything, but I think I might not be searching correctly.



thank you for helping

____________
Pendle
 
Hi

5000 static HTML files is quite bad idea. Even if your web server is serving static files, those should be generated based on some template(s) so you can re-generate them whenever needed.

There would be a couple of ways :
[ul]
[li]JavaScript with or without AJAX : needs a script block or scrip file included in each HTML file, the inserted note will not be part of the page content[/li]
[li]iframe : needs an [tt]iframe[/tt] tag in each HTML file, the inserted note will not be part of the page content[/li]
[li]SSI : needs a special tag in each HTML file, needs server configuration, the inserted copyright note will be part of the page content[/li]
[li]static generator : needs a special tag in each HTML file, the inserted copyright note will be part of the page content[/li]
[/ul]

Personally I would prefer to use a static generator. Of course, given the amount of files probably not a readily available one, but a custom made. If the HTML files already contain the copyright note, then would use [tt]sed[/tt] or some other text processing tool to transform it into something templateish ( like "{{copyright}}" or "Copyright &copy; {{year}} {{owner}}" ) that can be easily replaced later with the actual content. If not contains the copyright note yet, would look for a suitable spot for it ( for example right before the closing [tt]</body>[/tt] tag ) and insert the mentioned templateish thing.

Of course, we could suggest more suitable solution if we could see one such HTML file.


Feherke.
feherke.github.io
 
Hello

Thank you for replying. These files I inherited when the person who used to run the website had to give up and I offered to help (!)

Here is the text of one of the files


[pre]
<?php include("/home/iomfhsi/public_html/IOMFHS/password_protect.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The Isle of Man Family History Society</title>
<link href="../../../p7spepper/wills.css" rel="stylesheet" type="text/css" />
<link href="p7pmm/p7PMMv15.css" rel="stylesheet" type="text/css" media="all" />
<style type="text/css">
</style>
<script type="text/javascript" src="p7pmm/p7PMMscripts.js"></script>
</head>
<body>
<div id="outer">
<div id="inner">
<div id="masthead">
<img name="masthead" src="../../../p7spepper/img/masthead.jpg" width="900" height="145" border="0" id="masthead" alt="Masthead Image" />
</div>
<div id="contentwrapper">
<div class="maincolumn">
<div class="maincontent">

<h2>Transcript of Will of<br /></h2>
<h1>Christian Comish als Cubon, 1677 </h1>

<hr class="trans">


<pre>
blah blah blah transcription text
blah blah blah transcription text
blah blah blah transcription text

</pre>
<hr class="trans">
<p>
Submitted by: Name of transcriber<br />
Date: 23 April 2007 <br />
Original: LDS: 0991643 <br />
</p>

</div>
</div>
<div class="sidebarwrapper">
<div class="sidebarbox">
<div id="p7PMM_1" class="p7PMMv15">
</div>
</div>
</div>
<div class="clearfloat">&nbsp;</div>
</div>
<div class="footer">
<div class="footercolumn1">
<p>&copy; 2015 The Isle of Man Family History Society<br />Registered Charity No: 680 ISSN No: 1351-556X</p>
</div>
<div class="footercolumn2">
<p align="right"><a href=" </div>
</div>
</div>
</div>
</body>
</html>
[/pre]


thank you for helping

____________
Pendle
 
Hi

Ah, so they are not static HTML. And the copyright note is already there. Then I would run a command like this :
Code:
sed -i 's/&copy; 2015/\&copy; <?=date("Y")?>/' /path/to/file/*
This will replace the currently hardcoded "2015" with PHP code that always inserts the current year.

Note that the [tt]-i[/tt] option means in-place, so the files specified as parameters will be modified. Make sure you create backup copies of those 5000++ files before using that command.

Also note that if your files are organized in multiple directories, you have to take care in running the above command for each.


Feherke.
feherke.github.io
 
Thank you, I'll give that a go.

thank you for helping

____________
Pendle
 
To extend feherke's sed solution

you could use find and sed combined as a one line shell command


Code:
find . -type f -iname "*.php" -exec sed -i 's/&copy; 2015/\&copy; <?=date("Y")?>/' {} +





Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top