国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php正則獲取關鍵字、標題、網頁描述代碼

2024-09-04 11:47:24
字體:
來源:轉載
供稿:網友

本文章來給大家介紹關于php正則獲取關鍵字、標題、網頁描述代碼,有需要了解的同學可進入參考.

獲取關鍵字,代碼如下:

  1. function get_keywords($html
  2. $html=strtolower($html); 
  3. preg_match("@<head[^>]*>(.*?)</head>@si",$html$regs);  
  4. $headdata = $regs[1]; 
  5. preg_match("/<meta +name *=["']?keywords["']? *content=["']?([^<>"]+)["']?/i", $headdata$res); 
  6. if (isset ($res)) { 
  7. $keywords = $res[1]; 
  8. if ($keywords == ""$keywords = "無"
  9. $keywords=replace_word(textcut($keywords,250)); 
  10. $keywords=str_replace("-",",",$keywords); 
  11. $keywords=str_replace(",",",",$keywords); 
  12. $keywords=str_replace(" ",",",$keywords); 
  13. $keywords=str_replace("|",",",$keywords); 
  14. $keywords=str_replace("、",",",$keywords); 
  15. $keywords=str_replace(",,",",",$keywords); 
  16. $keywords=str_replace("<","",$keywords); 
  17. $keywords=str_replace(">","",$keywords); 
  18. return addslashes(trim($keywords)); 

獲取標題,代碼如下:

  1. function get_title($html
  2.   $html=strtolower($html); 
  3.  $title = str_replace(" - ",",",cut($html,"<title>""</title>" )); 
  4. //if ($title == "") $title = "無標題"; 
  5. if ($title$title=replace_word(textcut($title,80)); 
  6. if ($title$title=preg_replace("/<(.*?)>/","",$title); 
  7. return addslashes(trim($title)); 

獲取網頁描述description,代碼如下:

  1. function get_description($html
  2. $html=strtolower($html); 
  3. preg_match("@<head[^>]*>(.*?)</head>@si",$html$regs);  
  4. $headdata = $regs[1]; 
  5. preg_match("/<meta +name *=["']?description["']? *content=["']?([^<>"]+)["']?/i", $headdata$res); 
  6.       if (isset ($res)) { 
  7.        $description = $res[1]; 
  8.       } 
  9. if ($description == ""$description = "無"
  10. $description=replace_word(textcut($description,250)); 
  11. $description=str_replace("-",",",$description); 
  12. $description=str_replace(",",",",$description); 
  13. $description=str_replace(" ",",",$description); 
  14. $description=str_replace("|",",",$description); 
  15. $description=str_replace("、",",",$description); 
  16. $description=str_replace(",,",",",$description); 
  17. $description=str_replace("<","",$description); 
  18. $description=str_replace(">","",$description); 
  19. return addslashes(trim($description)); 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 望都县| 芒康县| 卢氏县| 沙田区| 寻甸| 紫金县| 青龙| 安康市| 阳山县| 靖安县| 灵山县| 齐河县| 滕州市| 建宁县| 渑池县| 都安| 洛浦县| 成武县| 北票市| 罗平县| 兴化市| 庆城县| 鄱阳县| 资源县| 蓝山县| 屯昌县| 奉贤区| 京山县| 乐清市| 灌南县| 威远县| 建宁县| 庄浪县| 鹤壁市| 巩义市| 清流县| 北宁市| 晋中市| 吐鲁番市| 尚义县| 黄龙县|