Assuming that what you whant to do in insert the contents of one file into your webpage, I have several options I'll discuss. Additionally, if what you want to do is select certain content out of another file and insert it in to your webpage I have very few options I can discuss with you.
[/hr]Inserting content from an outside source.[hr=0]IFRAMESThe <iframe> tag can be used to insert a file's content into your webpage. It will insert the entire file so you can actually show another website's page in your page.
The following code is the correct use of the <iframe> tag:
CODE
<IFRAME name="frame1" src="http://www.astahost.com/index.php" width=600 height=400 marginwidth=0 marginheight=0 frameborder=0 scrolling=auto></IFRAME>
That would insert the AstaHost forum index page into your page whereever you inserted the tag.
The IFRAME acts as a seperate entity inside your webpage and requires additionally coding to allow thw user to interact with the frame contents. The frames contents can't control the parents content so an IFRAME is not usable as a means of navigation of the website. Basically, you can't create a single link menu file for your website and use an IFRAME to insert it into you webpages.
[/hr]SSI (Server Side Includes)A server side include can be used to insert content into you webpage and gives much more control over what is displayed and how. Unlike the IFRAME, the SSI will directly insert the content into your webpage. As a result, the included content is a part of the main page and wil act like any other part of the webpage. Works great for headers, footers, menus, and advertisements.
An SSI is used like this:
First, create the content to be included:
(module1.html)
CODE
Search Engines:
- <a href="http://www.altavista.com>Alta Vista</a><br>
- <a href="http://www.excite.com>Excite</a><br>
- <a href="http://www.google.com>Google</a><br>
- <a href="http://www.lycos.com>Lycos</a><br>
- <a href="http://www.yahoo.com>Yahoo</a><br>
Then include that file in your main file like so:
(index.shtml)
CODE
<html>
<head>
<title>This is an SSI test</title>
</head>
<body>
Some Content Here!
<!--#include file="module1.html" -->
More Content Here!
</body>
</html>
The downside to using SSI is that not all servers have the option availible. As a result, there isn't a lot of information about the command because most people that would have wanted to use the feature didn't have access to it on their host. Another downside to using SSI is that you usually need to tell the server when you want to use it by using the .shtml file extention instead of the .html extention. So to add SSI to your entire website, you would need to change all of your HTML files to SHTML files and of course change all of your internal links. You would also need to update your url at any other websites that link to your website. I would suggest revamping the entire website and leave your index.html intact with a redirect to the index.shtml. This will reduce the number of broken links on your website.
[hr=0]PHP (PHP Hypertext Preprocessor)Using the PHP
include() or even
require() functions is similar to the SSI option. The real difference is that PHP will work on any host that has PHP enabled. It doesn't matter what version of PHP you have, this will work. Since PHP is so widely offered these days, it will be easy to use this command.
The PHP include function will include the contents of the entire file being included into the main PHP file. Like the SSI option, the content of the included file is inserted in raw form into the mainpage. So the file can include code bits, text, or html. The end user will have no idea that the page was put together from more than one file.
To use the include function you'll first need to write the file to be included. For today just reuse the module1.html file from the SSI section.
Since PHP will not interpret the contnents of the included file, you can give the file any extention that you want. It will just open the file and dump the contents into youe page where ever you insert the command.
Here is your PHP file.
(index.php)
CODE
<html>
<head>
<title>This is a PHP include test</title>
</head>
<body>
Some Content Here!
<?php include("module1.html"); ?>
More Content Here!
</body>
</html>
This will result in the same output as the SSI option.
Although there is wide support for PHP, you will still have the same setback as SSI in that you will need to tell the server when you want to use PHP by using the .php extention.
[/hr]Reading and using data from an outside source[hr=0]By no means should this process be considered easy considering the number of PHP functions you would need to learn before starting. I'll try to give a basic rundown of how this works.
First you'll need to know exactly what it is that you want from the remote file. This is used for displaying the user's weather on your website or even displaying your favorite stock quotes on your site. You'll need to figure out a way to identify that data only and ignore all of the rest of the files content. You'll need to used a number of regular expressions to filter the data. This is not an easy task and I couldn't begin to try and explain it all.
Next, you'll need to actaully read the file. To do this, you'll need to use the PHP get_file_contents() function. Once you have the contents you'll apply whatever method you came up with to filter out the unwanted data. Now all you need to do is output the data you retrieved.
Since this requires so much coding in PHP prior to even beginning to create your page, I don't recommend it for new PHP users.
[/hr]Here is a list of related resources that you may find helpful in deterimining which option to use or how to do use more advanced commands.[hr=0]- IFRAMES
- SSI
- PHP Include
- Remote File Reading
I hope that this information will be useful to you. If you have more questions regarding any of these options, please feel free to post them here or in a forum category that is directly related to the topic. I as well as many others will be happy to answer any further questions.
Good Luck

vujsa
Comment/Reply (w/o sign-up)