Pulling Information From A Text File

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
neobolt
Forum Newbie
Posts: 9
Joined: Wed Apr 14, 2004 7:43 pm

Pulling Information From A Text File

Post by neobolt »

What I am trying to do is have a single php page load jokes from text files.
So if the id# in the url is 7, then joke file 7.txt will load into the page.
Example:
http://www.smartmindmedia.com/jokes/bar/index.php?id=10
This link would load text file 10.txt into the webpage.

This is the code I have been trying.

Code: Select all

<?php

$content = file('http://www.smartmindmedia.com/jokes/bar/'.$_GET['id'].'.txt'); 
echo implode('', $content); 

?>
I don't really get an error from this. The index.php page just won't load.
If I remove this section of code the index.php page loads fine, but obviosly without the text being displayed.

Thanks for your help.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Try:

Code: Select all

<?php
include("http://www.smartmindmedia.com/jokes/bar/" . $_GET['id'] . ".txt");
?>
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

if you include it, it will parse any php in it, which may not be what you want

try

Code: Select all

$document = file_get_contents("http://www.smartmindmedia.com/jokes/bar/" . $_GET['id'] . ".txt");

echo $document;
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

rehfeld wrote:if you include it, it will parse any php in it, which may not be what you want

try

Code: Select all

$document = file_get_contents("http://www.smartmindmedia.com/jokes/bar/" . $_GET['id'] . ".txt");

echo $document;
if you echo it it will render html

better yet,

Code: Select all

<?
echo html_entities($document);?>
Post Reply