According to my statistics, someone performed a search engine query for the following:
"adding content from external file in html"
Assuming the the developer doesn't want to use FRAMES or IFRAMES to insert an external source into their webpage, a scripting language like PHP will need to be used.
In most cases, to get the server to use PHP, the file has to have the .php file extension. If you are working with existing HTML files, they'll need to be converted to PHP. There is already a tutorial available for this:
Converting HTML to PHP Basic Tutorial
Once you have your files converted or new files created with what every HTML you want to use to display your content as you normally do, you can begin to insert data from external text, HTML, PHP, or other files.
Imagine that you have a very basic webpage like so:
index.php
| Code: |
<html>
<head>
<title>Handy PHP Insert External Data Example</title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="vujsa">
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080">
Hello World!
</body>
</html>
|
The result would look like this:
QUOTE:
Hello World!
Then you could create a simple text file like so:
greeting.txt
| Code: |
Thank you for visiting Handy PHP!
|
If you modified the webpage like so:
index.php
| Code: |
<html>
<head>
<title>Handy PHP Insert External Data Example</title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="vujsa">
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080">
Hello World!<br />
<?php include('greeting.txt'); ?>
</body>
</html>
|
Which would display the following:
QUOTE:
Hello World!
Thank you for visiting Handy PHP!
It is important to note that data in the external file will be handle according to how you format it no matter what the file extension is.
So greeting.txt could be named greeting html and display the same.
If the file has HTML in it, the browser WILL convert that raw HTML into the displayed information you normally see in your browser. If you have PHP in your external file, then the server will execute that PHP code even if the file ends with something other than .php.
Using this type of external insertion allows for sections of you website that is identical on every page to be in a separate file allowing for only one file edit to change every page instead of having to open edit and save every file individually. This is great for site navigation menus that are the same on every page but may change from time to time.
Hope this helps.
vujsa