phpinfo() 显示 cURL 已启用,但我仍然无法使用它

发布于 2024-09-19 03:35:29 字数 262 浏览 4 评论 0原文

我正在制作页面获取脚本&我用的是curl。我使用了该函数:

get_data($url);

但我总是收到错误:

致命错误:在第 16 行 D:\wamp\www\grab\grab.php 中调用未定义的函数 get_data()

我正在使用 WAMP 服务器我已经在所有ini文件中启用了curl扩展,我已经检查了扩展目录路径,但一切看起来都很好,但我仍然卡住了。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

悲歌长辞 2024-09-26 03:35:29

没有get_data功能!!

您必须自己编写一个代码:

function get_data($url) {
   $ch = curl_init();    
   curl_setopt($ch,CURLOPT_URL,$url);
   $data = curl_exec($ch);
   curl_close($ch);
   return $data;
}

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;
}
呆萌少年 2024-09-26 03:35:29

使用此功能。没有 get_data 函数:

<?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/");
?>

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/");
?>
荭秂 2024-09-26 03:35:29

我不是使用 cUrl 的专家...但我从未听说过 get_data() 函数是 cUrl 的一部分。

http://es.php.net/manual/en/book.curl。 php

要进行查询,您必须创建一个curl实例:

$curl = curl_init( $url );

然后您可以使用以下命令执行查询:

curl_exec( $curl );

...基本上。

使用 curl_setopt (http://es. php.net/manual/en/function.curl-setopt.php)您可以设置各种选项(我确信您需要这样做)。

一个特别有用的选项是,使curl更容易使用:

curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );

这使得curl_exec()返回一个包含响应内容的字符串。

所以整个例子的结尾是这样的:

   $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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文