【发布时间】:2010-12-26 22:31:16
【问题描述】:
我正在尝试使用这段代码首先检索存储在我服务器上的 txt 文件中的 URL 并将其保存为变量,然后使用我刚刚检索并保存为的 URL 第二次运行 file_get_contents多变的。
代码适用于第一个 file_get_contents 并回显存储的 URL,但无法在第二个 file_get_contents 中使用该 URL 来回显 URL 的内容。
<?php
$files = file_get_contents('http://example.com/txtfile.txt');
echo $files;
$file = file_get_contents($files);
echo $file;
?>
【问题讨论】:
-
回显 $files 会得到什么结果?
-
txtfile.txt中有什么内容? -
可能包含一些空格,或者 URL 需要进行 urlencoded。试试 file_get_contents(trim($files));
-
$files 回显给了我存储在 txt 文件中的 URL。
-
@Andrew 为什么不回答这个问题。
标签: php file-get-contents