国产探花免费观看_亚洲丰满少妇自慰呻吟_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)); 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 贺兰县| 和平县| 中山市| 突泉县| 佳木斯市| 满城县| 任丘市| 旅游| 瓮安县| 原平市| 四川省| 马关县| 黎川县| 措勤县| 合水县| 凌云县| 库车县| 扎囊县| 江津市| 扶余县| 滨州市| 临澧县| 金门县| 彭水| 汕头市| 涞源县| 安化县| 泽普县| 高平市| 咸宁市| 吉隆县| 化隆| 宁波市| 福建省| 宁阳县| 东宁县| 清水县| 宁国市| 大理市| 临洮县| 阆中市|