日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內(nèi)最全I(xiàn)T社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > php開源 > php教程 > php實現(xiàn)文章內(nèi)容關(guān)鍵字增加內(nèi)鏈

php實現(xiàn)文章內(nèi)容關(guān)鍵字增加內(nèi)鏈

來源:程序員人生   發(fā)布時間:2014-04-10 00:25:20 閱讀次數(shù):4704次

網(wǎng)站文章自動增加站內(nèi)鏈接這個我想大多數(shù)據(jù)同學(xué)的網(wǎng)站都有這個功能,下面小編總結(jié)了三種文章內(nèi)鏈自動增加的功能,從上往下,最好的方法在最上面。

例1,代碼如下:

  1. /**  
  2. *對內(nèi)容中的關(guān)鍵詞添加鏈接  
  3. *只處理第一次出現(xiàn)的關(guān)鍵詞,對已有鏈接的關(guān)鍵不會再加鏈接,支持中英文  
  4. *$content:string 原字符串  
  5. *$keyword:string  關(guān)鍵詞  
  6. *$link:string,鏈接  
  7. */  
  8. function yang_keyword_link($content,$keyword,$link){  
  9.     //排除圖片中的關(guān)鍵詞  
  10.     $content = preg_replace( '|(<img[^>]*?)('.$keyword.')([^>]*?>)|U''$1%&&&&&%$3'$content);  
  11.     $regEx = '/(?!((<.*?)|(<a.*?)))('.$keyword.')(?!(([^<>]*?)>)|([^>]*?</a>))/si';  
  12.     $url='<a href="'.$link.'">'.$keyword.'</a>';  
  13.     $content = preg_replace($regEx,$url,$content,1);  
  14.     //還原圖片中的關(guān)鍵詞  
  15.     $content=str_replace('%&&&&&%',$keyword,$content);  
  16.     return $content;  

例2,代碼如下:

  1. include_once(dirname(__file__)."/../db/DBViewSpot.php" ); 
  2. class InnerLink{ 
  3.     private static $spotUrlMap
  4.     /** 
  5.      * Generate view spots keywords link 
  6.      * 
  7.      * @param string $description 
  8.      * @param array $spotUrlMap 
  9.      * @return string 
  10.      */ 
  11.     public static function genSpotLink($basePath$description
  12.     { 
  13.         if(emptyempty(InnerLink::$spotUrlMap)){ 
  14.             InnerLink::$spotUrlMap = DBViewSpot::getSpotPare(); 
  15.         } 
  16.         // 排除不規(guī)則數(shù)據(jù) 
  17.         if ( emptyempty($description)) { 
  18.             return $description
  19.         } 
  20.         foreach (InnerLink::$spotUrlMap AS $spotUrlPair){ 
  21.             $replace = "<a target='_blank' href='http://pzg412403.blog.163.com/blog/".$basePath."/".$spotUrlPair[1].".html'>".$spotUrlPair[0]."</a>"
  22.             // 描述里面只有文字,沒有圖片,所以只要注意 a 鏈接 
  23.             $tmp1 = explode("<a",$description); 
  24.             $is_replaced=false; 
  25.             foreach ($tmp1 as $key=>$item){ 
  26.                 $tmp2 = explode("</a>",$item); 
  27.                 if (sizeof($tmp2)>1) { 
  28.                     if (substr($tmp2[0],0,1)!="a" && substr($tmp2[0],0,1)!="A"){ 
  29.                         if ($is_replaced===false) { 
  30.                             $tmp2[1] = InnerLink::str_replace_once($spotUrlPair[0],$replace,$tmp2[1],$is_replaced); 
  31.                         } 
  32.                         $tmp1[$key] = implode("</a>",$tmp2); 
  33.                     } 
  34.                 }else { 
  35.                     if (is_string($item) && $is_replaced===false) { 
  36.                         $tmp1[$key] = InnerLink::str_replace_once($spotUrlPair[0],$replace,$item,$is_replaced); 
  37.                     } 
  38.                 } 
  39.             } 
  40.             $description = implode("<a",$tmp1); 
  41.         } 
  42.         return $description
  43.     } 
  44.     /** 
  45.      * replace key word for one time 
  46.      * 
  47.      * @param string $needle 
  48.      * @param string $replace 
  49.      * @param string $haystack 
  50.      * @param bool $is_replaced 
  51.      * @return string 
  52.      */ 
  53.     private static function str_replace_once($needle$replace$haystack,&$is_replaced) { 
  54.         $pos = strpos($haystack$needle); 
  55.         if ($pos === false) { 
  56.             return $haystack
  57.         } 
  58.         $is_replaced=true; 
  59.         return substr_replace($haystack$replace$posstrlen($needle)); 
  60.     } 

例3,這個是自己最初學(xué)php時寫的,感覺有點問題,代碼如下:

  1. <?php   
  2.     $keys =array(   
  3.          array('網(wǎng)頁特效','/js_a/js.html'),   
  4.          array('seo','/seo/seo.html'),   
  5.          array('php','/phper/php.html'),   
  6.          array('jsp','/jsp/jsp.html'),   
  7.          array('asp','/asp/asp.html'),   
  8.          array('ps','/fw/photo.html'),   
  9.          array('photoshop','/fw/photo.html'),   
  10.          array('javascript','/js_a/js.html'),   
  11.          array('.net','/net/net.html'),   
  12.          array('非主流','/fw/photo.html'),   
  13.          array('網(wǎng)絡(luò)','/mon/mon.html'),   
  14.          array('css','/cssdiv/css.html'),   
  15.          array('平面設(shè)計','/fw/photo.html'),   
  16.          array('網(wǎng)站','/person/'),   
  17.          array('網(wǎng)頁制作','/wy/yw.html'),   
  18.          array('搜索引擎','/seo/seo.html'),   
  19.          array('優(yōu)化','/seo/seo.html'),   
  20.          array('動畫','/flash_a/flash.html'),   
  21.          array('數(shù)據(jù)庫','/database/database.html'),   
  22.          array('掙錢','/mon/mon.html'),   
  23.          array('運營','/mon/mon.html')   
  24.              
  25.     );   
  26.            
  27.     $str ="今天是2010年5月30號,我的網(wǎng)站出現(xiàn)的問題這對seo有很多的問題,seo就是搜索引擎優(yōu)化了,以前學(xué)php好啊現(xiàn)在覺得jsp好,css+div,網(wǎng)頁,網(wǎng)頁設(shè)計,網(wǎng)頁制作,網(wǎng)頁學(xué)習(xí),網(wǎng)頁教學(xué),Photoshop,Flash,HTML,CSS,Dreamweaver,Fireworks,ASP,PHP,JSP,ASP.NET,網(wǎng)站建設(shè),網(wǎng)站開發(fā),網(wǎng)頁特效,平面設(shè)計,個人網(wǎng)站,網(wǎng)頁素材";   
  28.       
  29.       
  30.     echo $str,"<br>";   
  31.     foreach($keys as $nkeys){   
  32.            //print_r($nkeys);echo"<br>";   
  33.            //foreach( $nkeys as $join) {   
  34.            //echo($join),"<br>";   
  35.            if(strpos($str,$nkeys[0]) ){   
  36.                  $str =str_replace($nkeys[0],"<a href=http://www.phpfensi.com".$nkeys[1]." target=_blank >".$nkeys[0]."</a>",$str);       
  37.            }   
  38.            //}   
  39.     }   
  40.            
  41.        echo $str;   
  42.     ?>
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: www激情com| 2024国产精品视频 | 成人亚洲精品 | 亚洲香蕉在线观看 | 自拍偷拍欧美日韩 | 欧美 日韩 综合 | 免费a级毛片大学生免费观看 | 日韩高清一区二区 | 一区二区三区福利 | 91精品国产精品 | 粉嫩久久99精品久久久久久夜 | 国产精品入口麻豆九色 | 日韩欧美在线观看视频 | 亚洲一区二区久久久 | 日韩精品在线看 | 国产第一页在线 | 天堂成人国产精品一区 | 国内黄色片 | 99精品免费久久久久久久久日本 | 精品久久亚洲 | 国产精品美女久久久久久久网站 | 国产精品久久久久久影视 | 黄色裸体网站 | 日本三级网址 | 99久久综合 | 欧美日韩精品一区 | 国产精品久久久久久久免费看 | 一级毛片在线免费看 | 999成人免费视频 | 黄网址在线观看 | 精品一区二区三区免费 | 精品一级 | 亚洲国产精品久久 | av一区二区三区在线播放 | 成人手机在线免费视频 | 九九久久99 | 久久久久久国产精品 | 黄色免费视频在线观看 | 亚洲精品一区二区三区在线 | 国产一卡二卡三卡 | 美女网站视频在线观看 |