View Full Version : inserting a txt file into an html document?

Jimmy D
08-11-2007, 09:15 AM
I have an html document and i'd like to insert words from a txt file into a paragraph in the document. e.g/

<p> text from txt file </p>

is there a way to do this? have tried google but nothing really.


08-11-2007, 09:20 AM
Just copy and paste.

Jimmy D
08-11-2007, 09:57 AM
but i want it to be linked so i can changed the txt file independent of the html file

08-11-2007, 10:00 AM
not sure how to do it. but id be guessing you would have to use something like php to get that to work. or javascript. don't know as don't know either language.

08-11-2007, 10:06 AM
<a href="mytextfile.txt">READ my Text File</a>
The <a href="mytextfile.txt"> is the reference, followed by what you want displayed on the page, followed by a closing </a>

Using <p> la de da </p> Is just inserting la de da then a new paragraph. You don't actually require a closing </p> for paragraph it is optional.

Jimmy D
08-11-2007, 10:47 AM
Thanks Bantu. not exactly what i was looking for but helpful nonetheless :)
perhaps there is javascript that will do this?

08-11-2007, 01:33 PM
I'd steer clear of javascript for this - the only way you can do it with Javacsript is with XMLHTTPRequest, and I doubt you want the hassle (and a lot of people disable javascript anyway). The easiest way would be to just stick the text file in an iframe:
<iframe src="http://example.com/yourfile.txt"></iframe>Make sense? Note that you will probably need to apply styles to the iframe, it'll be damn ugly and probably the wrong size otherwise.

09-11-2007, 09:53 AM
Use the <pre> tag to give preformatted text including all your newlines. You need to paste the text document inside <pre> and </pre> to make it preserve all the newlines, etc. It will also preserve whitespace so be careful!