BlackWhite
BlackWhite

Reputation: 832

How get content from specific link?

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

Answers (2)

Funk Forty Niner
Funk Forty Niner

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

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

Related Questions