【发布时间】:2012-03-13 02:56:55
【问题描述】:
所有, 我有以下代码:
$context = stream_context_create(array(
'http' => array(
'timeout' => 5 // Timeout in seconds
)
));
$username = $options['account'];
$contents = file_get_contents( "https://api.twitter.com/1/statuses/user_timeline.json?screen_name={$username}&count=1", 0, $context );
当我执行此代码时,它工作正常。但是,当我将内容更改为此时:
$how_many = $options['how_many'];
$contents = file_get_contents( "
https://api.twitter.com/1/statuses/user_timeline.json?screen_name={$username}&count={$how_many}", 0, $context );
我收到以下错误:
警告:file_get_contents(https://api.twitter.com/1/statuses/user_timeline.json?screen_name=Username&count=10) [function.file-get-contents]:打开流失败:没有错误
任何想法为什么它适用于一个而不适用于另一个。如果我将该 URL 复制并粘贴到浏览器中,也会返回结果。
【问题讨论】:
-
检查 $context 是否真的存在,或者你错过了把它放在你的帖子上。
-
您在第二个示例的第一行中拼错了
$how_many。 -
您确定这与
$how_man与$how_many不同吗? -
这是一个错字。我更新了我的问题。
标签: php file-get-contents