Display information from a text file in a HTML document

Niwa Rose

macrumors newbie
Original poster
Oct 17, 2008
28
0
Utah
Okay all, I've come across a difficult situation. I want to take a text file that has all the information on a page (not HTML code) and have it display on a Web Page. I've tried tutorials using PHP and JavaScript, but none of them have worked for me. Help is much appreciated.
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,857
7
USA
PHP:
<?php
include 'file.txt';
?>
Server Side Includes (SSI)
Code:
<!--#include virtual="file.txt"-->
If you need further help, show what you've tried.
 
Comment

Niwa Rose

macrumors newbie
Original poster
Oct 17, 2008
28
0
Utah
I want information in a text file to show up in a Web page. For example, I can just edit the text information and it will change the text on the Web page, without dealing with the XHTML code. It's called a PHP include for the php solution.
 
Comment

Niwa Rose

macrumors newbie
Original poster
Oct 17, 2008
28
0
Utah
PHP:
<?php
include 'file.txt';
?>
Server Side Includes (SSI)
Code:
<!--#include virtual="file.txt"-->
If you need further help, show what you've tried.
I know where to put the PHP code, where do you put the commented code though?
 
Comment

Niwa Rose

macrumors newbie
Original poster
Oct 17, 2008
28
0
Utah
^^ So I just place it in the web document? The code I have so far is...

Code:
<html>
<head>

</head>
<title>test</title>
<body>
<?php
include 'testfile.txt';
?> 
<!--#include virtual="testfile.txt"-->

</body>
</html>
It is saved as a html file. Another question, would I need it to be on a server?
 
Comment

angelwatt

Moderator emeritus
Aug 16, 2005
7,857
7
USA
It is saved as a html file. Another question, would I need it to be on a server?
If the file has a .html extension, then the web server needs to be configured to parse .html files for PHP. Also, the server needs to be setup to use SSI for .html files (some do by default). You'll need to run it on a server for both the PHP and SSI to work as they are both server-side languages.
 
Comment

Niwa Rose

macrumors newbie
Original poster
Oct 17, 2008
28
0
Utah
If the file has a .html extension, then the web server needs to be configured to parse .html files for PHP. Also, the server needs to be setup to use SSI for .html files (some do by default). You'll need to run it on a server for both the PHP and SSI to work as they are both server-side languages.
That's probably why it hasn't been able to work. Is there a way I can accomplish the same thing using JavaScript?
 
Comment

rickiac

macrumors newbie
Dec 10, 2007
25
0
Try changing the file extension

When using the SSI, try using .shtml instead of .html. This has worked for me in the past. I have used a text file as a footer multiple pages, when I needed to make a change I just updated the .txt file.
 
Comment

JohnDoe8450

macrumors member
Feb 3, 2009
61
0
Seriously though, PHP includes are definitely the way to go. If you've got MAMP installed the following code should do juste fine...

PHP:
<html>
<head>

</head>
<title>test</title>
<body>
<?php
include 'testfile.txt';
?>

</body>
</html>
 
Comment

Niwa Rose

macrumors newbie
Original poster
Oct 17, 2008
28
0
Utah
Thanks all, I finally got it to work. The probably was I wasn't testing it on a server and that I didn't rename my html file as a php file. xD
 
Comment

Similar threads

Replies
1
Views
818
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.