Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi everyone. I have the following problem:
I'd like to include a basic little news section on my site for which i'd like to read out a text file and have that text displayed on my html page. The reason why i want to use textfiles is because the news bar is on almost every page and i dont want to go about having to change it on every page once the news change.
Now I know this is possible with SSI in SHTML but I have a feeling my host doesnt support that. I know way too little of ASP or PHP to do it in that as well.
Now the question is...is it possible via a javascript or even HTML code to load text from a .txt into the HTML page?
Thx up front
Dark KartugWar sucks but the sound is good and WE are the DJ's

Including a file in every page is a very simple piece of code. Here it is using the three most popular methods.
SSI/ASP
PHP
<?php include("filename.ext"); ?>
Personally, I prefer PHP because it is an altogether more straightforward language — in my opinion, anyway.
All you would need to do then is have a file, e.g. "news.inc", and modify and include one of the commands above appropriately. Then, when you edit news.inc, it will be immediately reflected on all pages.

Damn, the SSI/PHP code got filtered out (funny, it was showing fine on the preview). Look at the end of the second paragraph on this page.

If your host does not support PHP, ASP or one of the other scripting languages, you can use the poor man's method by using JavaScript.
There are two elements to this. First on any page where you want the text to show put this code:
<script language="javascript" src="thesourcefile.js"></script>
Note: the name of the file can be anything you want and you will need to include the path to that file in the src name as well.
Second, create the file (with notepag or another text editor). The file could go like this:
-------------Begin Script-------------
news = "Hello, todays news is as follow...";document.write(news);
-------------End Script-------------Of course you could use some variables and such to include the current date/time, etc.

ok sweet thanks to the both of you. I'll start with the Javascript first because I dont have time right now to check if PHP and ASP will work...But Im sure that it wont be a problem to get solved later on :).
Thanks so much
Cheers
Dark_Kartug

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |