分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

php一些实用的自制方法

发布时间:2023-09-06 02:13责任编辑:胡小海关键词:暂无标签

//json乱码转中文

function decodeUnicode($str){ ?return preg_replace_callback(‘/\\\\u([0-9a-f]{4})/i‘, ???create_function( ?????‘$matches‘, ?????‘return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE");‘ ???), ???$str);}

curl爬虫

function _grab($curl,$postInfo=‘‘,$cookie=‘‘,$referer=‘‘,$userAgent=‘‘){ ????$ch = curl_init(); ??????curl_setopt($ch, CURLOPT_URL, $curl); ??????//不输出头 ????curl_setopt($ch, CURLOPT_HEADER, 0); ???????//以字符串返回获取的信息,不直接输出 ????curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); ????//如果是https链接,不验证证书 ????if(preg_match(‘/https/i‘, $curl)){ ????????curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); ????} ????//POST ????if($postInfo){ ???????curl_setopt($ch,CURLOPT_POST,1); ???????curl_setopt($ch,CURLOPT_POSTFIELDS,$postInfo); ????} ????//加入cookie ????if($cookie){ ????????curl_setopt($ch,CURLOPT_COOKIE,$cookie); ????} ????//模拟来路 ????if($referer){ ????????curl_setopt($ch, CURLOPT_REFERER, $referer); ????} ????//模拟环境 ????if($userAgent){ ????????curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); ????} ????//执行 ????$content = curl_exec($ch); ??????//错误处理 ????if ($content ?=== false) { ????????return "网络请求出错: " . curl_error($ch); ????????exit(); ??????} ??????return $content;}

php一些实用的自制方法

原文地址:https://www.cnblogs.com/cl94/p/9606524.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved