Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

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.
 
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 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.
 
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?
 

^^ 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?
 
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.
 
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?
 
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.
 
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>
 
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.