Jump to content

[SOLVED] reading another webpage.


keeps21

Recommended Posts

I have the following function.

 

It is designed to read a webpage and then show the contents.

 

It works fine on my localhost, but not on the live server, only outputting "Subject: ", $subject isn't shown at all.

 

Any ideas why?

 

<?php
function get_music_player() {
error_reporting(E_ALL);
$url = "www.example.com";

$subject = join('', file($url)); 

return "Subject:  " . $subject;
}
?>

 

The file using the function is as follows.

echo get_music_player();

Link to comment
Share on other sites

<?php
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
?>

 

curl_exec

Link to comment
Share on other sites

Yet another question for you.

 

I'm noticing that curl_exec($ch) is outputting the contents of the webpage straight away.

 

How do I assign the contents to a variable so that I can then process it?

 

$contents = curl_exec($ch);

 

The above is just outputting the contents.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.