Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can text in a .txt file be displayed on a webpage?

5 views
Skip to first unread message

John Anderson

unread,
Feb 14, 2008, 10:27:29 AM2/14/08
to
Hi.

I'm wanting to make it so that the text on my web page is stored on a text
file on the Server so that when people access the website the browser reads
the text from the file and places it in the correct place on the Website. I
want to do this so that if I want to edit the text, all I have to do is edit
the information in the file and it automatically updates on the website.
This means I don't have to search through all the HTML to find the bit of
text I wish to edit. It also means that I'm less likely to edit the HTML by
mistake and screw the page up.

It's a bit like how you put a picture on to a website, except with text.

Can it be done, and if so, how?

Many thanks.

Bob Masta

unread,
Feb 15, 2008, 7:15:19 AM2/15/08
to

I'm not sure exactly what you are looking for, but it sounds like you
may just want to take a page of "body" text that contains no links or
headers or different font sizes, and insert that into an HTML page
that has surrounding links, banners, and whatever.

If so, it may be simpler to just set up the main HTML page so that
there is a space for you to paste in this text. You can treat it as
a "boilerplate" situation where you just merge in your text.

If you want to do this literally, you will have to make the space
for the text be a <PRE> ... </PRE> section, and be sure to use
only plain ASCII text. Otherwise, all the paragraph breaks in your
text will be ignored, and everything will flow together into one
monster paragraph. Note that with <PRE> you will need to decide
on your own line widths, since there is no auto-formatting of
paragraphs. Also note that the font will be monospaced, which may be
good if you want to include ASCII tables or whatever, but may look
ugly compared to the surrounding HTML fonts.

An alternative is to prepare your text by inserting <P> and </P>
around each paragraph. Depending on your coding skills, you can
make a little utility to do this for you. I use a variant of this
approach to create Help pages that can be posted onto my Website
surrounded by boilerplate HTML. I create my originals in plain ASCII
text, but which includes my own special "escape codes". Then I use
separate special-purpose programs to insert this text into the
boilerplate HTML, add the <P>s, and convert the escape codes into
links, etc.

If you go the custom utility route like this, you can start out just
adding <P>s, and manually paste it into your HTML. Then you can
move to having your utility doing it automatically, then go on to add
fancier features.

Best regards,

Bob Masta

DAQARTA v3.50
Data AcQuisition And Real-Time Analysis
www.daqarta.com
Scope, Spectrum, Spectrogram, FREE Signal Generator
Science with your sound card!

John Anderson

unread,
Feb 15, 2008, 8:18:21 AM2/15/08
to
I'm wanting it so that there will be a number of .txt files on the Server.
All these files will include text I want to appear on the page.

I want to know if there is a way of making the text in these .txt files to
appear on the webpage.

Then if I want to edit the text, all I do is edit the text in the .txt
files, meaning I can leave the actual .html file well alone.

Can this be done?

Cheers.

"Bob Masta" <NoS...@daqarta.com> wrote in message
news:47b57c2...@news.sysmatrix.net...

John Anderson

unread,
Feb 15, 2008, 8:37:30 AM2/15/08
to
Btw, I've already tried:

<div>
<?php include("text.txt"); ?>
</div>

and

<pre><!-- #include virtual="text.txt" --></pre>

but they wouldn't work. Is there any other way of doing this in a .html
file?

Cheers,
John.

"Bob Masta" <NoS...@daqarta.com> wrote in message
news:47b57c2...@news.sysmatrix.net...

Adrienne Boswell

unread,
Feb 15, 2008, 10:03:51 AM2/15/08
to
Gazing into my crystal ball I observed "John Anderson"
<john.an...@yahoo.co.uk> writing in
news:mAgtj.95119$g46....@fe58.usenetserver.com:

Find out what is available on the server. You might not have access to
SSI on the server - get a new host.

--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share

rccsa...@gmail.com

unread,
Feb 16, 2008, 5:31:24 AM2/16/08
to
acftually,i want to say how i implement banner through php.i want the
code

Pete Lees

unread,
Feb 16, 2008, 8:01:57 AM2/16/08
to
John,

> I'm wanting to make it so that the text on my web page is stored on a
> text file on the Server so that when people access the website the
> browser reads the text from the file and places it in the correct
> place on the Website.

If more sophisticated methods are unavailable to you, JavaScript "includes"
could be the way to go.

1) In a plain text editor like Notepad, create a file that contains the text
strings you want to reuse throughout your Web site. For example:

string1 = "A simple example.";
string2 = "An example containing <strong>HTML</strong> markup.";
string3 = "Use a backslash as an \"escape\" character.";
string4 = "<table cellspacing='5'>" +
"<tr>" +
"<td><img src='ms_logo.gif' alt='Microsoft logo' /></td>" +
"<td>" +
"<strong>Microsoft Corporation</strong><br />" +
"One Microsoft Way<br />" +
"Redmond, WA<br />" +
"98052<br />" +
"United States" +
"<p><em>Where do you want to go today?</em></p>" +
"</td>" +
"</tr>" +
"</table>";

2) Save this file as, for example, "global.js".

3) Link the JavaScript file to each HTML file via a <script> element in the
<head> section.

<head>
<title>This is the topic title</title>
<script type="text/javascript" src="global.js"></script>
</head>

4) At the point in each HML file where you want to insert some reusable
text, add a <script> element like this:

<script type="text/javascript">document.write(string1)</script>

where the value in parentheses identifies the string that you want to
insert.

Pete


Adrienne Boswell

unread,
Feb 16, 2008, 12:01:03 PM2/16/08
to
Gazing into my crystal ball I observed "Pete Lees"
<pd....@btinternet.com> writing in
news:JdadneNB37xBQyva...@bt.com:

> If more sophisticated methods are unavailable to you, JavaScript
> "includes" could be the way to go.
>

Of course you realize that users without js are not going to get the
content. That would include Google and other SEs.

John Anderson

unread,
Feb 18, 2008, 7:15:34 AM2/18/08
to
Sounds good, I'll give it a go.

I'm wanting it for an eBay Template I'm working on, so I hope it works on
eBay.

Cheers.

"Pete Lees" <pd....@btinternet.com> wrote in message
news:JdadneNB37xBQyva...@bt.com...

0 new messages