Page 1 of 1

Pulling Information From A Text File

Posted: Sun Oct 31, 2004 11:02 am
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.

Posted: Sun Oct 31, 2004 12:17 pm
by d3ad1ysp0rk
Try:

Code: Select all

<?php
include("http://www.smartmindmedia.com/jokes/bar/" . $_GET['id'] . ".txt");
?>

Posted: Sun Oct 31, 2004 4:55 pm
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;

Posted: Sun Oct 31, 2004 5:04 pm
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);?>