正则提取页面标签内容
public function tel(){
// header('Content-type:text/html;charset=GBK');
$url='https://shouji.supfree.net/fish.asp?cat='.$_REQUEST['tel'];
$str=$this->httpsRequestlison($url,'');
$str=iconv("GB2312","UTF-8",$str);//GB2312转换为utf-8
preg_match('/<p><span class="bgreen">归属地:<(.*?)>(.*?)<\/p>/i', $str, $mach);
var_dump($mach[2]);exit;
}
function httpsRequestlison($url, $data = null){
$ch = curl_init();
//设置url
curl_setopt($ch, CURLOPT_URL, $url);
//设置curl_exec方法的返回值,结果返回,不自动输出任何内容
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if(!empty($data)){
//发送post请求,
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
//跳过ssl检查项
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//发送请求
$result = curl_exec($ch);
curl_close($ch);
return $result;
}