100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > PHP远程获取网页内容

PHP远程获取网页内容

时间:2019-01-22 21:43:42

相关推荐

PHP远程获取网页内容

后端开发|php教程

quot,regex,function,return,title

后端开发-php教程

1.截取php类文件 主要包括 获取url的html内容 然后从html内容中进行正则表达式匹配

网站下载器源码,vscode元素样式提示,使用ubuntu很卡,tomcat支持多个证书,麂皮爬虫,php 支付宝 签名验证,徐汇seo优化哪里有,在线免费算命网站源码,帝国 ecms081模板lzw

include StringBuilder.php;class CutPage{function __construct(){}//方法一:连接 获取真个文件的文本内容function getAllContent($url){$resouce=fopen($url, "r") or die("文件打开失败!");if(!$resouce){echo "请求文件不存在!";}//$allc//长度太短了取不全用自购建的stringbuilder$sb=new StringBuilder();while(!feof($resouce)){//如果没有到文件的结尾则继续向下执行$line=fgets($resouce,4096);$sb->append($line);}fclose($resouce);return $sb->toString();}//方法二:获取所有的文本进行文本title的匹配---------格式为:xxxx(xx)xxx的形式表达式function matchContentTitle($content,$regex_title){//echo "regex:".$regex_title;if(preg_match($regex_title, $content)){$array=preg_split($regex_title, $content,-1,PREG_SPLIT_DELIM_CAPTURE);return $array[1];}else{echo "匹配失败!";}}//匹配章节 返回携带章节的arrayfunction matchContentChapter($content,$regex_chapter){if(preg_match_all($regex_chapter, $content,$matcher)){return $matcher[1];}else{echo "匹配失败!";return ;}}}

圈圈quan.php源码,ubuntu怎么撤销粘贴,tomcat找不到的原因,遇见爬虫图片,php怎么使用memcache,seo搜索引擎之站外优化lzw

测试php文件

php开发宝典源码下载,vscode做词云,ubuntu 升级18,tomcat部署项目流程,爬虫族瞳孔,php fpm 是什么,浙江seo网络推广价格价位,教育网站模板下载,网站 模板 htmllzw

include CutPage.php;class Test{publicstatic function start($url,$regex_title,$regex_chapter){$cut=new CutPage();$all=$cut->getAllContent($url);$returnTitle=$cut->matchContentTitle($all, $regex_title);echo "题目:".$returnTitle;$arrays=$cut->matchContentChapter($all, $regex_chapter);for($i=0;$i<count($arrays);$i++){echo $arrays[$i];}}}$url="/xiaoshuo/12/12816/";//正则表达式$regex_title="/\s*[[(\S+)[[\s*/";$regex_chapter="/\s*[](\W+)[\s*/";//章Test::start($url, $regex_title, $regex_chapter);//echo "cut".$return;//匹配汉字的正则表达式^[\u4E00-\u9FA5]+

这里构建了一个类似JAVA中的一个StringBuilder类

class StringBuilder{ const LINE="

"; protected $list= array(\); public function __construct( $str=NULL) { array_push($this->list,$str); } public function append($str) { array_push($this->list,$str); return $this; } public function appendLine($str) { array_push($this->list,$str.self::LINE); return $this; } public function appendFormat( $str,mixed $args) { array_push($this->list, sprintf($str,$args)); return $this; } public function toString() { return implode("",$this->list); } public function __destruct() { unset($this->list); }}

以上就介绍了PHP远程获取网页内容,包括了正则表达式方面的内容,希望对PHP教学有兴趣的朋友有所帮助。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。