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));
}
php正则获取网页标题、关键字、网页描述代码的更多相关文章
- Python2获取网页标题
Python获取网页标题 使用Python2.x的urllib2和lxml,速度应该还快于BeautifulSoup4(话说回来,为什么大家都要用BS4呢?一个XPATH不就完了吗) 没有安装过的,用 ...
- html网页标题
HTML代码 <html> <head> <!--<title>定义网页标题,显示在浏览器的标题--> <title>网页标题</ti ...
- (转)asp.net动态设置标题title 关键字keywords 描述descrtptions
方法一 if (!IsPostBack){//Page title网页标题Page.Title = “我的网站标题”;//须将网页head标签设成服务器控件模式,即<head runat=&qu ...
- Vue动态修改网页标题
业务需求,进入页面的时候,网页有个默认标题,加载的网页内容不同时,标题需要变更. 例:功能授权,功能授权(张三). Vue下有很多的方式去修改网页标题,这里总结下解决此问题的几种方案: 一.最笨方案 ...
- jquery无法修改网页标题,无法修改网页标题
今天遇到一个问题,搜索时动态修改网页标题,用jquery的这段代码无效,无论FF还是IE $("title").html("new title"); 后来只好用 ...
- 获取WebView里的网页文本内容
获取WebView里的网页文本内容,能够採用例如以下方法: public class ComJSInterface { public void loadHtmlContent(String conte ...
- JS获取屏幕,浏览器窗口大小,网页高度宽度(实现代码)_javascript技巧_
JS获取屏幕,浏览器窗口大小,网页高度宽度(实现代码)_javascript技巧_--HTML5中文学习网 http://www.html5cn.com.cn/shili/javascripts/79 ...
- Chrome扩展程序——TabCopy:一键复制网页标题和网址
Chrome扩展程序——TabCopy:一键复制网页标题和网址 - Erik_ly的博客 - CSDN博客 https://blog.csdn.net/u012318074/article/detai ...
- php 微信登录 公众号 获取用户信息 微信网页授权
php 微信登录 公众号 获取用户信息 微信网页授权 先自己建立两个文件: index.php 和 getUserInfo.php index.php <?php //scope=snsap ...
随机推荐
- ASP.NET MVC 路由调试工具Router Debugger
直接上图 安装好手动启用或关闭 我开始调试我之前程序中由于路由遇到的问题 当发出 http://localhost:2362/109.html 这样请求, 我的意图是想Article的Details被 ...
- ubuntu 13.10 skype登不上问题
首先打开sources.list sudo gedit /etc/apt/sources.list 如果是13.10添加源: deb http://archive.canonical.com/ubun ...
- 【leetcode】Word Search
Word Search Given a 2D board and a word, find if the word exists in the grid. The word can be constr ...
- Android 自动化测试 常用的命令----随时更新
常用命令分为三类,如下: 1. android android sdk : 打开SDK管理器. android avd : 打开虚拟设备管理器. android --help : 查看帮助信息. 2. ...
- Qt 子窗体嵌入父窗体
1.创建个子窗体QDialog.在子窗体构造函数添加 Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { u ...
- Linux下常用的硬件信息查看命令
1.查看CPU型号,这里为了方便查看结合管道符用grep进行了匹配,当然只需要前面的命令也可以,命令如下: cat /proc/cpuinfo | grep "model name" ...
- 24. javacript高级程序设计-最佳实践
1. 最佳实践 l 来自其他语言的代码约定可以用于决定何时进行注释,以及如何进行缩进,不过JavaScript需要针对其松散类型的性质创造一些特殊的约定 l javascript应该定义行为,html ...
- 7.SpringMVC注解优化
新建controller,每个人都可以建自己的controller,比较方便,不用再在web.xml中进行配置,value的请求地址一定要唯一. 优化: 1.上面示例中spring-annotatio ...
- pair<>结构体模版的用法
1.pair算是一个结构体模版,定义的时候是这样的: pair<T1,T2> P; 其中T1,T2可以是int,string,double,甚至是vector<>. 2.进行初 ...
- linux 增加用户 useradd 用法小结及配置文件说明
转自CSDN,http://blog.csdn.net/warden2010/article/details/5132290,谢谢作者 在Linux 系统中,所有的用户和组像一个国家.如果国家要繁荣昌 ...