一个我经常用到的采集网页数据抓取网页获取数据的PHP函数类
class get_c_str { var $str; var $start_str; var $end_str; var $start_pos; var $end_pos; var $c_str_l; var $contents; function get_str($str,$start_str,$end_str){ $this->str = $str; $this->start_str = $start_str; $this->end_str = $end_str; $this->start_pos = strpos($this->str,$this->start_str)+strlen($this->start_str); $this->end_pos = strpos($this->str,$this->end_str); $this->c_str_l = $this->end_pos - $this->start_pos; $this->contents = substr($this->str,$this->start_pos,$this->c_str_l); return $this->contents; } } //使用方法 $url = ‘http://www.xiaodoubi.com‘; $data = file_get_contents($url); $get_c_str = new get_c_str; $content = $get_c_str -> get_str($data,‘<p class="message">‘,‘</p>‘); echo $content;
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。