博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php正则获取网页标题、关键字、网页描述代码
阅读量:6186 次
发布时间:2019-06-21

本文共 1837 字,大约阅读时间需要 6 分钟。

php正则获取网页关键字,代码如下:
function get_keywords($html){$html=strtolower($html);preg_match("@
]*>(.*?)@si",$html, $regs);$headdata = $regs[1];preg_match("/
"]+)["']?/i", $headdata, $res);if (isset ($res)) {$keywords = $res[1];}if ($keywords == "") $keywords = "无";$keywords=replace_word(textcut($keywords,250));$keywords=str_replace("-",",",$keywords);$keywords=str_replace(",",",",$keywords);$keywords=str_replace(" ",",",$keywords);$keywords=str_replace("|",",",$keywords);$keywords=str_replace("、",",",$keywords);$keywords=str_replace(",,",",",$keywords);$keywords=str_replace("<","",$keywords);$keywords=str_replace(">","",$keywords);return addslashes(trim($keywords));}
 

  

php正则获取网页标题,代码如下
function get_title($html){  $html=strtolower($html); $title = str_replace(" - ",",",cut($html,"", "" ));//if ($title == "") $title = "无标题";if ($title) $title=replace_word(textcut($title,80));if ($title) $title=preg_replace("/<(.*?)>/","",$title);return addslashes(trim($title));}
 

  

php正则获取网页描述description,代码如下
function get_description($html){$html=strtolower($html);preg_match("@
]*>(.*?)@si",$html, $regs);$headdata = $regs[1];preg_match("/
"]+)["']?/i", $headdata, $res); if (isset ($res)) { $description = $res[1]; }if ($description == "") $description = "无";$description=replace_word(textcut($description,250));$description=str_replace("-",",",$description);$description=str_replace(",",",",$description);$description=str_replace(" ",",",$description);$description=str_replace("|",",",$description);$description=str_replace("、",",",$description);$description=str_replace(",,",",",$description);$description=str_replace("<","",$description);$description=str_replace(">","",$description);return addslashes(trim($description));}
 

 

转载于:https://www.cnblogs.com/qhorse/p/5067378.html

你可能感兴趣的文章
LinkedHashMap的实现原理
查看>>
shell 判断语句
查看>>
oracle闪回操作详解
查看>>
浅谈身份、数字身份与电子签约的关系
查看>>
小微企业不注册商标的严重后果
查看>>
2018-11-07 直播笔记
查看>>
正向解析DNS服务
查看>>
ospf与eigrp通过修改管理距离实现路由的负载
查看>>
Oracle 数据库的备份与恢复
查看>>
PLSQL异常处理
查看>>
Oracle 11g r2全外连接优化执行计划(三)
查看>>
tomcat
查看>>
Jenkins 部署
查看>>
我的友情链接
查看>>
考虑碰撞的二能级原子和电磁场的相互作用
查看>>
Python 端口扫描 报警
查看>>
VM虚拟机redhat7 不能上网
查看>>
C# 转义符
查看>>
《机器学习实战》Logistic回归
查看>>
Android短信验证码倒计时
查看>>