fopen returns Resource id #4

那年仲夏 提交于 2019-12-20 03:56:10

问题


<?php
$handle = fopen("https://graph.facebook.com/search?q=mark&type=user&access_token=2227470867|2.mLWDqcUsekDYZ_FQQXYnHw__.3600.1279803600-100001317997096|YxS1eGhjx2rpNYLNE9wLrfb5hMc.", "r");
echo $handle;
?>

Why does it echo Resource id #4 instead of the page itself?


回答1:


Because fopen returns a resurce pointer to the file, not the content of the file. It simply opens it for subsequent reading and/or writing, sependent on the mode in which you opened the file.

You need to fread() the data from the resource referenced in $handle.

This is all basic stuff that you could have read for yourself on the manual pages of php.net




回答2:


Once you have created your $handle you now need to fread() the contents.

$contents = ''; 
while (!feof($handle)) 
{ 
$contents .= fread($handle, 8192); 
} 
fclose($handle); 
echo $contents; 

source: php.net/manual/en/function.fread.php




回答3:


Use

<?php
    $data = file_get_contents("https://graph.facebook.com/search?q=mark&type=user&access_token=2227470867|2.mLWDqcUsekDYZ_FQQXYnHw__.3600.1279803600-100001317997096|YxS1eGhjx2rpNYLNE9wLrfb5hMc.", "r");
    echo $data;
?>



回答4:


Because fopen return the resource handle of the file it opened not the contents.



来源:https://stackoverflow.com/questions/3308388/fopen-returns-resource-id-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!