Reputation: 3098
I am in the process of making a page fetch script & I was using curl for it. I used the function:
get_data($url);
but I always get the error:
Fatal error: Call to undefined function get_data() in D:\wamp\www\grab\grab.php on line 16
I am using WAMP server and I have enabled curl extentions in all the ini files, I have checked the extensions directory path but everything seems fine and I am still stuck.
Upvotes: 2
Views: 4275
Reputation: 8067
I'm not an expert using cUrl... but I've never heard about that get_data() function being part of cUrl.
http://es.php.net/manual/en/book.curl.php
To make a query you must create a curl instance:
$curl = curl_init( $url );
And then you can execute the query with:
curl_exec( $curl );
...basically.
With curl_setopt (http://es.php.net/manual/en/function.curl-setopt.php) you can set various options (I'm sure you will need to).
One option specially useful that makes curl even easer to use is:
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
This makes curl_exec() to return a string with the content of the response.
So the whole example ends like:
$url = 'http://www.google.com';
$curl = curl_init( $url );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
$content = curl_exec( $curl );
echo "The google.com answered=".$content;
Upvotes: 2
Reputation: 46692
Use this function. There is no get_data
function:
<?php
function file_get_contents_curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
echo file_get_contents_curl("http://www.google.com/");
?>
Upvotes: 2
Reputation: 455132
There is not get_data
function!!
You'll have to code one yourself as:
function get_data($url) {
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
Upvotes: 5