1

I have some 1000 html pages. I need to update the names which is present at the footer of every html page. What is the best possible efficient way of updating these html pages instead of editing each name in those html pages one by one.

Edit: Even if we use some sort of scripts, we have to make changes to every html file. One possible way could be using Editor function. Please share if anybody has any another way of doing it.

Aakash Deep
  • 114
  • 1
  • 7
  • 2
    Write a script on the server that uses a utility like `sed`. – Barmar Feb 09 '18 at 01:21
  • 1
    Most IDEs also provide a way to do search and replace in all the files in a project. – Barmar Feb 09 '18 at 01:22
  • Possible duplicate of [Replace words in the body text](https://stackoverflow.com/questions/5558613/replace-words-in-the-body-text) – caiovisk Feb 09 '18 at 01:24
  • 1
    Considering all your files are most likely `.html`, none of the answers will work for you. You'll just need to use an app (IDE) with the ability for mass find/replace (I like BBEdit for that, mac only though), or boil your own commandline mayhem with grep and cat and sed and whatever whatever (something I don't do, because I love bbedit for that haha). – IncredibleHat Feb 09 '18 at 01:40
  • Thanks guys for helping me out .Creating script is one of the option but for that also we need to go to each and every html page and make reference to that php file. I think the best way would be to use the IDE or editor function to do this as @IncredibleHat stated. – Aakash Deep Feb 10 '18 at 05:52

4 Answers4

0

I would suggest creating a php file with the content (in this case the name you want to add) call it something like footer.php like so

<?php
echo "name you want to add";
?>

then you include this php file in all your html files like so

<html>
<body>

<h1>Welcome to my home page!</h1>
<p>Some text.</p>
<p>Some more text.</p>
<?php include 'footer.php';?>

</body>
</html> 
Rheo
  • 165
  • 1
  • 2
  • 11
0

You can use domdocument and domxpath to parse the html file(you can use php file_get_contents to read the file )

it looks like i can't post links

0

PHP is the best option for this. You can create a 'footer.html' file (ideally in a different folder often named 'includes') and then use the require_once('./includes/footer.html') function to import the footer inside your page.

let's say the footer.html file looks something like this:

<footer>
    <p>{Text}</p>
</footer>

If you would like to change the content of the <p> element manually on each one of your page you will need to replace the string {text} every time on each page (Replace string in text file using PHP)

Or you may use variables like so:

footer.php

<footer>
    <p><?php echo $text ?></p>
</footer>

page.php

html content...

<?php 
$text = "your text here"
require_once("./includes/footer.php") 
?>
IchooseMe
  • 1
  • 2
-1

Try this. you must create a footer.php file then change all names you need to change

footer.php
<?php
<footer> test </footer>

?>

Then replace your footer in every html file by this code.

  index.php
<?php

include 'footer.php';

?>

NOTE: This code is only for the same names of every footer.

Noriel
  • 218
  • 1
  • 7