Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 897
ilhan Avatar asked Oct 21 '25 08:10

ilhan


2 Answers

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

like image 118
Mark Baker Avatar answered Oct 23 '25 23:10

Mark Baker


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

like image 27
PHPology Avatar answered Oct 23 '25 23:10

PHPology



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!