Yesterday, when I was using curl to write an api interface, I found that when running the curl function, I was prompted with a Call to undefined function curl_init() error. Judging from the error, the curl_init() function was not defined. Later I learned that this function requires PHP to be enabled. A file in, the specific method is as follows.
This is how I wrote the program code
The code is as follows
代码如下 |
复制代码 |
??php
// 初始化一个 cURL 对象
$curl = curl_init();
// 设置你需要抓取的URL
curl_setopt($curl, CURLOPT_URL, 'http://www.bKjia.c0m');
// 设置header
curl_setopt($curl, CURLOPT_HEADER, 1);
// 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// 运行cURL,请求网页
$data = curl_exec($curl);
// 关闭URL请求
curl_close($curl);
// 显示获得的数据
var_dump($data);
|
|
Copy code
|
??php
//Initialize a cURL object
$curl = curl_init();
//Set the URL you need to crawl
curl_setopt($curl, CURLOPT_URL, 'http://www.bKjia.c0m');
//Set header
curl_setopt($curl, CURLOPT_HEADER, 1);
//Set cURL parameters to require the results to be saved in a string or output to the screen.
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//Run cURL and request the web page
$data = curl_exec($curl);
| //Close URL request
curl_close($curl);
//Display the obtained data
var_dump($data);
The result prompts: Call to undefined function curl_init(). Later, Baidu provided some solutions for your reference.
Modify configuration under windows+apache:
1. Modify php.ini and remove the semicolon in front of ;extension=php_curl.dll
2. Copy the two files libeay32.dll and ssleay32.dll (C:AppServphp5) to the system32 directory
3. Restart Apache (services.msc)
linux+apache solution:
The curl package needs to be installed. If you use ubuntu, open the Synaptic package manager, search for curl, and install curl
http://www.bkjia.com/PHPjc/632132.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632132.htmlTechArticleYesterday when I was using curl to write an api interface, I found that when running the curl function, it prompted Call to undefined function curl_init() Error, judging from the error, the curl_init() function is not defined, and then...