欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php curl使用

程序员文章站 2022-05-31 17:24:57
...
##### php curl使用php curl更改页面信息```/*$curlobj = curl_init();//初始化curl_setopt($curlobj,CURLOPT_URL,"http://www.baidu.com");  //设置访问页面的urlcurl_setopt($curlobj,CURLOPT_RETURNTRANSFER,true);     //执行后不直接打印出来$output = curl_exec($curlobj);                          //执行curl_close($curlobj);                                       //关闭curlecho str_replace("百度","DLL",$output);*/```使用curl获取图片信息```header("Content-type: text/html; charset=utf-8");@header('Content-type:image/jpg');$ch = curl_init();$url="http://ww1.sinaimg.cn/mw690/78f2cc43jw1f2vtybda98j206y046t8y.jpg";curl_setopt($ch,CURLOPT_URL,$url);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $output = curl_exec($ch);$info = curl_getinfo($ch);file_put_contents("abc.jpg",$output);curl_close($ch);```使用curl模拟post表单,上传文件```$url = "http://localhost/phpcurl/out.php";$post_data = array(    "name" => "gewenrui",    "password" =>"123");$ch = curl_init();curl_setopt($ch,CURLOPT_URL,$url);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch,CURLOPT_POST,1);curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data);curl_setopt($ch,CURLOPT_TIMEOUT,10);$output = curl_exec($ch);$info = curl_getinfo($ch);//echo '获取'.$info['url'].'耗时'.$info['total_time'].'秒'.$info['request_size'];curl_close($ch);echo $output;上传文件$url = "http://localhost/phpcurl/out.php";$post_data = array(    "fool"  => "bar",    //上传文件此处需要添加@符号    "upload" => "@abc.jpg");$ch = curl_init();curl_setopt($ch,CURLOPT_URL,$url);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch,CURLOPT_POST,1);curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data);$output = curl_exec($ch);curl_close($ch);echo $output;```使用curl实现批处理j```
相关标签: php curl使用