2

Is there any way to get a simple php code that just displays the text from a txt document, that's on a url?

This is what I've got so far. I'm sure I'm missing something~

<?
$text = file_get_contents('https://dl.dropboxusercontent.com/u/28653637/Snip/Snip/Snip.txt');
fopen ($text)
?>

Guessing you can't open it, since it's not on the drive. Any workaround that, or fix you guys could help me with?

Thanks (:

Mansl
  • 21
  • 1
  • 2
  • file_get_contents has to be the easiest way. Anyway wanted to say; I think it's always safer to use than the short form ?> – Peter May 21 '13 at 19:44

2 Answers2

6

Too easy! :)

$text = file_get_contents('https://dl.dropboxusercontent.com/u/28653637/Snip/Snip/Snip.txt');
echo $text;

Explanation:

file_get_contents() will return the contents of the remote file and assign it to the $text variable. Then you'll just have to ouput these contents using the echo statement

Alternative: use the readfile() function. It will output the contents of the file directly:

readfile('https://dl.dropboxusercontent.com/u/28653637/Snip/Snip/Snip.txt');
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
1

You don't have to open it. It's already appended as a string to the variable $text.

$text = file_get_contents('https://dl.dropboxusercontent.com/u/28653637/Snip/Snip/Snip.txt');
echo $text;
//Outputs "“Why Don't You Get A Job?” ― The Offspring"
Abdulaziz
  • 2,201
  • 1
  • 21
  • 35
  • Just a simple song title displayer, that's easier to read, more or less what I'm trying to do :) – Mansl May 21 '13 at 20:01