
你说的是筛选两个br之间 的内容么
$pattern="/^<br/>(这个小括号可以省略,如果是要筛选所有内容,就用\S,如果只要数字,就用\d,如果是字母,就是[a-z])<br/>$/";
function getRemoteRes($url, $postfields = NULL,$timeout=60) {
$ci = curl_init ();
curl_setopt ( $ci, CURLOPT_URL, $url );
curl_setopt ( $ci, CURLOPT_HEADER, FALSE );
curl_setopt ( $ci, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt ( $ci, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt ( $ci, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt ( $ci, CURLOPT_TIMEOUT, $timeout );
curl_setopt ( $ci, CURLOPT_POST, TRUE );
if (is_array ( $postfields )) {
$field_str = "";
foreach ( $postfields as $k => $v ) {
$field_str = "&$k=" urlencode ( $v );
}
curl_setopt ( $ci, CURLOPT_POSTFIELDS, $field_str );
}
$response = curl_exec ( $ci );
if (curl_errno ( $ci )) {
return 'ERRNO!';
} else {
$>
一、用file_get_contents函数,以post方式获取url
<php
$url= '>
$data= array('foo'=> 'bar');
$data= >
$opts= array(
'>
'method'=> 'POST',
'header'=>"Content-type: application/x->
"Content-Length: " strlen($data) "\r\n",
'content'=> $data
)
);
$ctx= stream_context_create($opts);
$html= @file_get_contents($url,'',$ctx);
二、用file_get_contents以get方式获取内容
<php
$url='>
$html= file_get_contents($url);
echo$html;
>
三、用fopen打开url, 以get方式获取内容
<php
$fp= fopen($url,'r');
$header= stream_get_meta_data($fp);//获取报头信息
while(!feof($fp)) {
$result= fgets($fp, 1024);
}
echo"url header: {$header} <br>":
echo"url body: $result";
fclose($fp);
>
四、用fopen打开url, 以post方式获取内容
<php
$data= array('foo2'=> 'bar2','foo3'=>'bar3');
$data= >
$opts= array(
'>
'method'=> 'POST',
'header'=>"Content-type: application/x->
urlencoded\r\nCookie:cook1=c3;cook2=c4\r\n"
"Content-Length: " strlen($data) "\r\n",
'content'=> $data
)
);
$context= stream_context_create($opts);
$html= fopen('>
$w=fread($html,1024);
echo$w;
>
五、使用curl库,使用curl库之前,可能需要查看一下phpini是否已经打开了curl扩展
<php
$ch= curl_init();
$timeout= 5;
curl_setopt ($ch, CURLOPT_URL, '>
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents= curl_exec($ch);
curl_close($ch);
echo$file_contents;
>
以上就是关于php curl 获取到网页内容后 使用preg_match_all 筛选信息 正则不怎么会写全部的内容,包括:php curl 获取到网页内容后 使用preg_match_all 筛选信息 正则不怎么会写、用php获取指定网页内容、php获取指定网页内容等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)