当前位置: 首页 > news >正文

php正则获取网页标题、关键字、网页描述代码

php正则获取网页关键字,代码如下:

function get_keywords($html)
{
$html=strtolower($html);
preg_match("@<head[^>]*>(.*?)</head>@si",$html, $regs);
$headdata = $regs[1];
preg_match("/<meta +name *=["']?keywords["']? *content=["']?([^<>"]+)["']?/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,"<title>", "</title>" ));
//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("@<head[^>]*>(.*?)</head>@si",$html, $regs);
$headdata = $regs[1];
preg_match("/<meta +name *=["']?description["']? *content=["']?([^<>"]+)["']?/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

相关文章:

  • centos 6.4配置samba+ldap认证
  • 理解并取证:以太通道的动态协商机制的工作原理
  • Linux内核跟踪之trace框架分析【转】
  • 转 C#图像处理(各种旋转、改变大小、柔化、锐化、雾化、底片、浮雕、黑白、滤镜效果)...
  • [ 2222 ]http://e.eqxiu.com/s/wJMf15Ku
  • Spring-AOP
  • Exchange2013下Telnet发送测试邮件失败及解决方案
  • 《FPGA全程进阶---实战演练》之搞定阻抗匹配
  • VI编辑常用命令
  • Redux系列x:源码分析
  • 12.28作业
  • 微信开发学习路线
  • ceph集群配置注意事项
  • AngularJs 父子级Controller传递数据
  • httpd.conf
  • 《用数据讲故事》作者Cole N. Knaflic:消除一切无效的图表
  • 【399天】跃迁之路——程序员高效学习方法论探索系列(实验阶段156-2018.03.11)...
  • 002-读书笔记-JavaScript高级程序设计 在HTML中使用JavaScript
  • CentOS 7 修改主机名
  • ERLANG 网工修炼笔记 ---- UDP
  • Flex布局到底解决了什么问题
  • Markdown 语法简单说明
  • React-Native - 收藏集 - 掘金
  • Redis字符串类型内部编码剖析
  • spring boot下thymeleaf全局静态变量配置
  • Spring声明式事务管理之一:五大属性分析
  • vue-cli在webpack的配置文件探究
  • 服务器从安装到部署全过程(二)
  • 前端存储 - localStorage
  • 一道面试题引发的“血案”
  • 与 ConTeXt MkIV 官方文档的接驳
  • 远离DoS攻击 Windows Server 2016发布DNS政策
  • 转载:[译] 内容加速黑科技趣谈
  • const的用法,特别是用在函数前面与后面的区别
  • 带你开发类似Pokemon Go的AR游戏
  • 关于Kubernetes Dashboard漏洞CVE-2018-18264的修复公告
  • 没有任何编程基础可以直接学习python语言吗?学会后能够做什么? ...
  • ​决定德拉瓦州地区版图的关键历史事件
  • (1)Nginx简介和安装教程
  • (10)工业界推荐系统-小红书推荐场景及内部实践【排序模型的特征】
  • (WSI分类)WSI分类文献小综述 2024
  • (三)Honghu Cloud云架构一定时调度平台
  • (十一)c52学习之旅-动态数码管
  • (一)认识微服务
  • (转)C语言家族扩展收藏 (转)C语言家族扩展
  • (转)Unity3DUnity3D在android下调试
  • .libPaths()设置包加载目录
  • .NET(C#、VB)APP开发——Smobiler平台控件介绍:Bluetooth组件
  • .net操作Excel出错解决
  • /usr/bin/perl:bad interpreter:No such file or directory 的解决办法
  • ??myeclipse+tomcat
  • @RequestBody与@ModelAttribute
  • @Transactional 竟也能解决分布式事务?
  • [ 蓝桥杯Web真题 ]-Markdown 文档解析
  • [20140403]查询是否产生日志