<?php
header("Content-type:text/html; charset=utf-8");
$pattern = '/xxx(.*)yyyy/isU'; //i 不区分大小,s表示点号匹配换行 U 防贪婪匹配
$url = "";
$ch = curl_init($url);
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page 以字符流返回不输出浏览器
// CURLOPT_HEADER => false, // don't return headers
// CURLOPT_FOLLOWLOCATION => true, // follow redirects
// CURLOPT_ENCODING => "", // handle all encodings
//CURLOPT_USERAGENT => "spider", // who am i
// CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
// CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
// CURLOPT_POST => 1, // i am sending post data
// CURLOPT_POSTFIELDS => $curl_data, // this are my post vars
// CURLOPT_SSL_VERIFYHOST => 0, // don't verify ssl
// CURLOPT_SSL_VERIFYPEER => false, //
// CURLOPT_VERBOSE => 1 //
);
curl_setopt_array($ch, $options);
$texts = curl_exec($ch);
if(preg_match($pattern, $texts, $arr)){
//$arr[0] 包含正则中的字符
// $arr[1] 不包含正则中的字符
}
if(preg_match_all($pattern, $texts, $arr)){
//返回一个二维数组,包含多次匹配数据
}
curl_close($ch);
?>
header("Content-type:text/html; charset=utf-8");
$pattern = '/xxx(.*)yyyy/isU'; //i 不区分大小,s表示点号匹配换行 U 防贪婪匹配
$url = "";
$ch = curl_init($url);
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page 以字符流返回不输出浏览器
// CURLOPT_HEADER => false, // don't return headers
// CURLOPT_FOLLOWLOCATION => true, // follow redirects
// CURLOPT_ENCODING => "", // handle all encodings
//CURLOPT_USERAGENT => "spider", // who am i
// CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
// CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
// CURLOPT_POST => 1, // i am sending post data
// CURLOPT_POSTFIELDS => $curl_data, // this are my post vars
// CURLOPT_SSL_VERIFYHOST => 0, // don't verify ssl
// CURLOPT_SSL_VERIFYPEER => false, //
// CURLOPT_VERBOSE => 1 //
);
curl_setopt_array($ch, $options);
$texts = curl_exec($ch);
if(preg_match($pattern, $texts, $arr)){
//$arr[0] 包含正则中的字符
// $arr[1] 不包含正则中的字符
}
if(preg_match_all($pattern, $texts, $arr)){
//返回一个二维数组,包含多次匹配数据
}
curl_close($ch);
?>