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

首頁(yè) > CMS > PhpCMS > 正文

phpcms v9關(guān)鍵字,內(nèi)聯(lián),關(guān)聯(lián)鏈接完美解決方案

2024-09-10 07:15:25
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

由于PHPCMS關(guān)鍵字關(guān)聯(lián)鏈接替換的時(shí)候 對(duì)ALT標(biāo)簽也會(huì)替換掉,還有A標(biāo)簽內(nèi)的東西也會(huì)替換掉 這樣不是我們的本意,搜遍論壇沒(méi)有解決方案,看到一個(gè)網(wǎng)站解決了,問(wèn)了下那個(gè)朋友,人家告訴我1000元,說(shuō)官方都沒(méi)有解決的問(wèn)題,你說(shuō)值不值1000,我就納悶了,自己研究了下DEDE和帝國(guó)的程序,搞明白了怎么回事,現(xiàn)在將研究的方法分享出來(lái).

找到include目錄下的global.func.php文件,用編輯軟件打開后,CTRL+F搜索function keylinks,然后找到如下代碼:

  1. function keylinks($txt$replacenum = '')  
  2. {  
  3. $linkdatas = cache_read('keylink.php','',1);  
  4. if($linkdatas)  
  5. {  
  6.   $word = $replacement = array();  
  7.   foreach($linkdatas as $v)  
  8.   {  
  9.    $word1[] = '/'.preg_quote($v[0], '/').'/';  
  10.    $word2[] = $v[0];  
  11.    $replacement[] = '<a href="'.$v[1].'" target="_blank" class="keylink">'.$v[0].'</a>';  
  12.   }  
  13.   if($replacenum != '')  
  14.   {  
  15.    $txt = preg_replace($word1$replacement$txt$replacenum);  
  16.   }  
  17.   else  
  18.   {  
  19.    $txt = str_replace($word2$replacement$txt);  
  20.   }  //Vevb.com 
  21. }  
  22. return $txt;  
  23. }  

替換成以下代碼:

  1. function keylinks($txt$replacenum = '')  
  2. {  
  3. $linkdatas =  
  4. cache_read('keylink.php','',1);  
  5.  
  6.  
  7. //暫時(shí)屏蔽超鏈接  
  8. $txt  
  9. = preg_replace("/(<a(.*))(>)(.*)(<)(//a>)/isU"'//1-]-//4-[-//6',  
  10. $txt);  
  11.  
  12. $GLOBALS['replaced'] = array();  
  13.  
  14.  
  15. if($linkdatas)  
  16. {  
  17.   $word = $replacement =  
  18. array();  
  19.   foreach($linkdatas as  
  20. $v)  
  21.   {  
  22.    $word[] =  
  23. $v[0];  
  24.    $GLOBALS['replaced'][$v[0]] =  
  25. 0;  
  26.    $replacement[] = '<a href="'.$v[1].'" target="_blank"  
  27. class="keylink">'.$v[0].'</a>';  
  28.   }  
  29. }  
  30. $txt  
  31. = preg_replace("/(^|>)([^<]+)(?=<|$)/sUe", "_highlight('//2', /$word,  
  32. /$replacement'//1',/$replacenum)", $txt);  
  33.  
  34.  
  35. //恢復(fù)超鏈接  
  36. $txt = preg_replace("/(<a(.*))-/]-(.*)-/[-(//a>)/isU"'//1>//3<//4'$txt); 
  37.  
  38. //高亮專用, 替換多次是可能不能達(dá)到最多次  
  39. function _highlight($string$words$result,  
  40. $pre ,$cfg_replace_num)  
  41. {  
  42. $string = str_replace('/"''"',  
  43. $string);  
  44. if($cfg_replace_num > 0)  
  45. {  
  46.   foreach  
  47. ($words as $key =>  
  48. $word)  
  49.   {  
  50.    if($GLOBALS['replaced'][$word] ==  
  51. 1)  
  52.    {  
  53.     continue;  
  54.    }  
  55.    $string  
  56. = preg_replace("/".preg_quote($word)."/"$result[$key], $string,  
  57. $cfg_replace_num);  
  58.    if(strpos($string$word) !==  
  59. false)  
  60.    {  
  61.     $GLOBALS['replaced'][$word]  
  62. =  
  63. 1;  
  64.    }  
  65.   }  
  66. }  
  67. else  
  68. {  
  69.   $string  
  70. str_replace($words$result$string);  
  71. }  
  72. return  
  73. $pre.$string;  
  74. }  

就ok了.

現(xiàn)在實(shí)現(xiàn)的功能是:

第一就是會(huì)替換所有的關(guān)聯(lián)關(guān)鍵字,第二如果替換次數(shù)在模型設(shè)置里面設(shè)置的是大于0的話,每個(gè)關(guān)鍵字只替換一次,主要考慮到替換太多,不利于SEO.

在生成速度上會(huì)慢些,還有就是在后臺(tái)加的關(guān)鍵字會(huì)全部替換,要是關(guān)鍵字太密集的話,也會(huì)不利于搜索引擎優(yōu)化,實(shí)現(xiàn)起來(lái)也不難.

要想一個(gè)關(guān)鍵字可以使用下面的代碼:

  1. //高亮專用, 替換多次是可能不能達(dá)到最多次  
  2. function _highlight($string$words$result$pre ,$cfg_replace_num)  
  3. {  
  4.  
  5. $string = str_replace('/"''"'$string);  
  6. if($cfg_replace_num > 0)  
  7. {  
  8. foreach ($words as $key => $word)  
  9. {  
  10. if($GLOBALS['replaced'][$word] == $cfg_replace_num)  
  11. {  
  12. continue;  
  13. }  
  14. $string = preg_replace("/".preg_quote($word)."/"$result[$key], $string$cfg_replace_num);  
  15. if(strpos($string$word) !== false)  
  16. {  
  17. $GLOBALS['replaced'][$word] ++;  
  18. }  
  19. }  
  20. }  
  21. else  
  22. {  
  23. $string = str_replace($words$result$string);  
  24. }  
  25. return $pre.$string;  
  26. }

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 兰州市| 临沭县| 报价| 屯门区| 水富县| 稻城县| 宜宾市| 新蔡县| 陵川县| 连城县| 荣昌县| 大连市| 南溪县| 沐川县| 阆中市| 文昌市| 邹城市| 吴川市| 永清县| 海淀区| 盐源县| 广昌县| 阿克苏市| 白沙| 曲阜市| 夹江县| 横峰县| 潢川县| 剑川县| 汾西县| 长沙市| 基隆市| 麻栗坡县| 清水县| 沾益县| 玛纳斯县| 株洲县| 青海省| 安顺市| 朝阳市| 滦平县|