Reputation: 832
I have link in specific variable eg.
$link = 'http://google.com'
and I try to get content from this link with function fopen. Eg. : $var = fopen("'".$link."'", "rb");
echo stream_get_contents($var); ,
but without success. Error is
Warning: file_get_contents('http://google.com'): failed to open stream: No such file or directory in /var/www/...
If I use directly
$var = fopen('http://google.com', "rb");
echo stream_get_contents($var)
this work perfectly? How do I fix this or what method to use if I link is a variable?
Upvotes: 0
Views: 273
Reputation: 74219
Based on your posted code, this worked for me. Try it using this method:
<?php
$link = "http://www.google.com";
$var = fopen($link, "rb");
echo stream_get_contents($var)
?>
Upvotes: 1
Reputation: 562
This always worked for me.
$url = 'http://google.com';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
Upvotes: 1