Grab from text file?

  • lomilmand
  • Student
  • Student
  • lomilmand
  • Posts: 91
  • Loc: Bournemouth, UK

Post 3+ Months Ago

:idea: Can part of a webpage be filled with the contents of a seperate text file?

Here's the situation.

A user profile...

Personal statment - [text]

but [text] would be replaced with the contents of a text file named "text.txt" for example?

Could this be done, and what would the code be. Surely it must be quite a simple thing to do without the need for ASP or PHP?

You may question why I want to do it this way, but I do want to give it a go. Lets asume the text file is in a folder named "profiles"


Thank you for your help.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Unfortunately you are going to need a server side script to do this.

The file has to be opened read and its contents returned, hence the need for PHP or ASP

Relatively easy in PHP though you might want to look into it
  • Sabu
  • Beginner
  • Beginner
  • Sabu
  • Posts: 47

Post 3+ Months Ago

I suppose you could, if you really *needed* to, set out the text file as a javascript function, then

Code: [ Select ]
<script type="text/javascript" language="javascript" src="profiles/user.txt"></script>


I haven't tested this myself, but what's stopping it?
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

Sabu wrote:
I suppose you could, if you really *needed* to, set out the text file as a javascript function, then

Code: [ Select ]
<script type="text/javascript" language="javascript" src="profiles/user.txt"></script>


I haven't tested this myself, but what's stopping it?


As soon as the browser loads said text file it's going to popup an error saying firstWordInTextFile undefined.

It will treat the first word in said file as a variable, hence the undefined :wink:

Building on what Rabid Dog mentioned earlier,
Without Server Side Scripting (ASP,PHP,CF,soOn) there is no way to be sure everyone will be able to see said text due to different browser settings.
  • Sulfin
  • Graduate
  • Graduate
  • User avatar
  • Posts: 129
  • Loc: canada

Post 3+ Months Ago

If you wan't to load it with
Code: [ Select ]
<script type="text/javascript" language="javascript" src="profiles/user.txt"></script>
The inside of that file must start with
Code: [ Select ]
document.write("
and end with
Code: [ Select ]
");
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

I'm pretty sure you would need a separate document.write() for each line. I used to do something like that to insert a large drop down menu of all the pages on my site by calling a function in a .js file that used multiple write() calls. Since the menu itself was dependent on javascript it worked out pretty well, since only those with js enabled saw the menu. If I remember correctly it wouldn't let me print multiple lines with one call to write(). I used a php script to create the .js file as it wasn't practical to do it manually and of course who actually saw it depended on the browser setup of the user, so I don't think javascript would work too well in this case.
  • Sulfin
  • Graduate
  • Graduate
  • User avatar
  • Posts: 129
  • Loc: canada

Post 3+ Months Ago

You could put an iframe with the content of the text file. I don't know how to take the border off though.
Code: [ Select ]
<iframe src="text.txt" width=100% height=100></iframe>
  • Hacker007
  • Proficient
  • Proficient
  • User avatar
  • Posts: 371
  • Loc: Riverside, CA

Post 3+ Months Ago

Code: [ Select ]
<iframe src="text.txt" width=100% height=100 FRAMEBORDER=0 SCROLLING=NO></iframe>

Not needed to be Caps, just made it caps so you would notice :D. Thats how to elimanat borders and scrollbars. That would make it look nicer.

Off of that, I have wanted to find this out too ;) My altrnative? XML still requires a coule tags in the XML document, but not to hard. ( http://www.geocities.com/soupnaz1/index.htm thats a site I made, If you look at the tables, the text is being read from an XML file. I dont know php, but good luck)

-throwing in random stuff Hacker007 ;)
  • lomilmand
  • Student
  • Student
  • lomilmand
  • Posts: 91
  • Loc: Bournemouth, UK

Post 3+ Months Ago

Well that works very well thank you. Just a few more questions.

How can I make the text wrap. So far it just streams on for one line, but I need it to wrap within this 'frame'.

Is it possible to change the background color?/text color?

Thank you for your help.
  • lomilmand
  • Student
  • Student
  • lomilmand
  • Posts: 91
  • Loc: Bournemouth, UK

Post 3+ Months Ago

anyone? please...
  • SharkShark
  • Guru
  • Guru
  • User avatar
  • Posts: 1013
  • Loc: Living In Today

Post 3+ Months Ago

Ok, Im not quite sure what you guys ended up doing here, but It appears you put it all in an iframe is that right? Well, the simplest thing to do would be to just put it in PHP. Insert the following code where you want the text file displayed:

Code: [ Select ]
<?php
include("page.txt");
?>
  1. <?php
  2. include("page.txt");
  3. ?>


The only thing you will have to do, is rename the ending of your page to .php. For instance "index.html" would become "index.php". This is really a much easier way to update or edit your pages. when I build a site, I place the code for my navigation, my header, my footer, and main content, in four different .txt files. I then call my main page index.php, insert the above code in the appropriate places, and there ya go. This is excellent if you have multiple pages with the same navigation on each one. Rather than having to edit the code on each page when you are adding or deleting, you simply insert your page, give every a .php extension, then all you have to edit is the .txt file that contains you navigation. That is how I would personally do things. All up to you however. :D

//edit: change "page.txt" to whatever the name of the text file is.
  • lomilmand
  • Student
  • Student
  • lomilmand
  • Posts: 91
  • Loc: Bournemouth, UK

Post 3+ Months Ago

But i don't need it to be php. Its not going to reach that level of enhancment. I just need the text to wrap in this frame if its possible, not that your answer isn't appreciated.
  • SharkShark
  • Guru
  • Guru
  • User avatar
  • Posts: 1013
  • Loc: Living In Today

Post 3+ Months Ago

ok, first of all, which one of the preceding suggestions did you actually use? If you used an iframe it should automatically be wrapping. which suggestion did you follow? and do you have a preview of the page or code for me to look at?

Post Information

  • Total Posts in this topic: 13 posts
  • Users browsing this forum: No registered users and 123 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.