/    Sign up×
Community /Pin to ProfileBookmark

displaying a text file in html

How do I display the contents of a text file as an HTML page ..?

The text file has an ever changing content as visitors come and go from my website – it is the content of this login page I would like to display as an HTML page..

thanx..

to post a comment
HTML

10 Comments(s)

Copy linkTweet thisAlerts:
@The_Little_GuyNov 17.2005 — Are you trying to display a txt file within an HTML file? If so you can't. Try Server side script.
Copy linkTweet thisAlerts:
@kiathauNov 17.2005 — Yape, server side script.

XML/XSLT would be a greate choice.

Try this, http://www.sitepoint.com/article/xmlxslt-driven-website-net

Kiat Hau,

http://webidiot.blogspot.com, Let's build your web site
Copy linkTweet thisAlerts:
@TheBearMayNov 17.2005 — Assuming the text is in a file called login.txt, something like this should work:

...
<script type="text/javascript">
/*<![CDATA [*/
function getFile(fileName){
oxmlhttp = null;
try{
oxmlhttp = new XMLHttpRequest();
oxmlhttp.overrideMimeType("text/xml");
}
catch(e){
try{
oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
return null;
}
}
if(!oxmlhttp) return null;
try{
oxmlhttp.open("GET",fileName,false);
oxmlhttp.send(null);
}
catch(e){
return null;
}
return oxmlhttp.responseText;
}
/*]]>*/
</script>
</head>

<body>
<div id="oPut"></div>
<script type="text/javascript">
document.getElementById("oPut").innerHTML=getFile("login.txt");
</script>
...
Copy linkTweet thisAlerts:
@tcurrierDec 09.2005 — This works for me ... but ... it doesn't seem to be recognizing the

carriage control/line feed characters, and the text lines all run together.

alabama

arizona

arkansas

show up as : alabama arizona arkansas

Do you know of a way around this problem ?

Thanks...
Copy linkTweet thisAlerts:
@CharlesDec 09.2005 — <iframe src="file.txt"><a href="file.txt">Text</a></iframe>
Copy linkTweet thisAlerts:
@NogDogDec 09.2005 — If PHP is available on your host it just takes one line of code:
[code=php]
<?php
##### BE SURE TO NAME THIS FILE WITH A .php SUFFIX #####
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
<head>
<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ISO-8859-1'>
<title>Include example</title>
<style type="text/css">
<!--
#text {
/* add desired styling for the included text here */
}
-->
</style>
</head>
<body>
<h1>Include example</h1>
<p id="text">
<?php
echo(nl2br(htmlentities(file_get_contents("/path/to/file.txt"))));
?>
</p>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@TheBearMayDec 09.2005 — Could also try changing the div tags to pre...
Copy linkTweet thisAlerts:
@thewebmanDec 09.2005 — pre tags are now deprecated.
Copy linkTweet thisAlerts:
@TheBearMayDec 09.2005 — pre tags are now deprecated.[/QUOTE]
As of ??? I see where the width attribute for <pre> has been deprecated as of HTML 4.01 http://www.w3.org/TR/html401/struct/text.html#h-9.3.4 but see nothing in it or the XHTML specs that alludes to the element itself being deprecated.
Copy linkTweet thisAlerts:
@tcurrierDec 09.2005 — This works, thanks !

<iframe src="file.txt"><a href="file.txt">Text</a></iframe>

I'm also looking to change the background color of the IFRAME.... I've looked for examples, but none of them seem to work.... Thanks for any help...
×

Success!

Help @glenvern spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...