简体   繁体   English

从URL txt获取文本

[英]Get text from URL txt

Is there any way to get a simple php code that just displays the text from a txt document, that's on a url? 有什么方法可以得到一个简单的PHP代码,该代码只显示txt文档中位于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 (: 谢谢 (:

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. file_get_contents()将返回远程文件的内容 ,并将其分配给$text变量。 Then you'll just have to ouput these contents using the echo statement 然后,您只需要使用echo语句输出这些内容

Alternative : use the readfile() function. 替代方法 :使用readfile()函数。 It will output the contents of the file directly: 它将直接输出文件的内容:

readfile('https://dl.dropboxusercontent.com/u/28653637/Snip/Snip/Snip.txt');

You don't have to open it. 您不必打开它。 It's already appended as a string to the variable $text . 它已经作为字符串附加到变量$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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM