php 正则表达式 取标题,关键词,内容代码
采集在现在的cms中都常常用到哦,下面我们就来看看关于php 正则表达式 取标题,关键词,内容代码源码哦。
<?php //获取标题 $inarr = array(); preg_match("/<title>(.*)<\/title>/isU", $body, $inarr); if (isset($inarr[1])) { $redatas['title'] = $inarr[1]; } //获取关键词 $inarr = array(); preg_match("/<meta[\s]+name=[\'\"]keywords[\'\"] content=[\'\"](.*)[\'\"]/isU", $body, $inarr); if (isset($inarr[1])) { $redatas['keywords'] = cn_substr(html2text($inarr[1]) , 30); } //获取摘要 $inarr = array(); preg_match("/<meta[s]+name=[\'\"]description[\'\"] content=[\'\"](.*)[\'\"]/isU", $body, $inarr); if (isset($inarr[1])) { $redatas['description'] = cn_substr(html2text($inarr[1]) , $cfg_auot_description); } //获取内容 if ($s != '' && $e != '') { $redatas['body'] = GetHtmlAreaA($s, $e, $body); if ($redatas['body'] != '' && $redatas['description'] == '') { $redatas['description'] = cn_substr(html2text($redatas['body']) , $GLOBALS['cfg_auot_description']); } }
本文地址:http://www.phprm.com/code/f3a34a7a06595591cc5cb07b4c2e9194.html
转载随意,但请附上文章地址:-)