Including text from a file to HTML file

Hi Experts,

Is there a way to display the contents of another text file.  For example,

<html><head><title></tille></head>

<body>

Some text from another text file....
</body>
</html>

I was thinking of doing this way, so that the article I want to include be in some text file and I don't have to change any of the html files for it.
ambuliAsked:
Who is Participating?
 
b0lsc0ttConnect With a Mentor IT ManagerCommented:
The simplest method is to use an iframe.  For example ...

<html><head><title></title></head>

<body>

<iframe src="filename.txt" width="200" height="200"></iframe>
</body>
</html>

Since you are using Apache you probably can use PHP (mentioned above).  It is a server side language and it could read the other file and insert the contents in the html page.  It would actually write the HTML too.  For example you can make a file called file.php and put the code below in it.

<html><head><title></tilte></head>

<body>

<?php
include 'filename.txt';
?>
</body>
</html>

When this file was run in the browser you would see the html and the contents of the other file.  Another option on Apache, but often disabled, is SSI (server side includes).  If it is enabled then you would use code like the one below and need to end this filename with .shtml.

<html><head><title></title></head>

<body>

<!--#include file="filename.txt" -->
</body>
</html>

Let me know how this helps or what additional info you need.

bol
0
 
JoeCommented:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<div>
<p>this is where you would copy the text</p>
</div>
</body>
</html>

Regards,

JoeZ430
0
 
gjutrasCommented:
what web server? IIS, apache  (version?)
What you want can probably be done with includes if they're turned on on your web site.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
ambuliAuthor Commented:
Hi, my web server is apache.  I am not sure if include is turned on there and is it something turned off usually?
0
 
ambuliAuthor Commented:
and could you show me an example of this?  Thanks,
0
 
JoeCommented:
You would have to use server side code. ASP, PHP, JSP etc..
0
 
b0lsc0ttIT ManagerCommented:
I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.