当前位置:Gxlcms > PHP教程 > phpcurl使用

phpcurl使用

时间:2021-07-01 10:21:17 帮助过:19人阅读

##### 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```                    

人气教程排行