简体   繁体   中英

fopen returns Resource id #4

<?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?

Because fopen() returns a resource pointer to the file, not the content of the file. It simply opens it for subsequent reading and/or writing, dependent 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

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

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;
?>

因为 fopen 返回的是它打开的文件的资源句柄而不是内容。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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