<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. php語言

    PHP關聯鏈接添加的方法

    時間:2025-03-15 11:00:37 php語言 我要投稿

    PHP關聯鏈接添加的方法

      為了優化內鏈,我們需要將內容添加上關鍵鏈接,那內容如果添加關聯鏈接呢,怎么添加呢?下面是小編為大家搜索整理的PHP關聯鏈接添加的方法,希望能給大家帶來幫助!更多精彩內容請及時關注我們應屆畢業生考試網!

      方法一:手動編輯添加

      方法二:使用程序在輸出內容時實現,又不影響后臺內容的編輯

      下面是PHP自動給文章內容添加關聯鏈接方法和示例:

      Keylinks函數方法:

      參數一:要處理的內容

      參數二:替換次數

      返回結果:處理后的內容

      header("Content-Type:text/html;charset=utf-8"); //設置編碼

      $linkdatas=array(

      array('前端開發', 'http://blog.kgula.com'),

      array('前端設計', 'http://blog.kgula.com'),

      array('Web前端', 'http://blog.kgula.com'),

      array('前端博客', 'http://blog.kgula.com'),

      );

      echo "替換前

      ";

      echo $str='Web前端開發 - 專注于網站前端設計與Web用戶體驗。前端開發,專注Web前端開發,關注Web用戶體驗,關注國內外最新最好的前端設計資源和前端開發技術的專業前端博客';

      echo "

      替換后

      ";

      echo $str=keylinks($str,2);

      /**

      * 關聯關鍵詞替換

      * @param txt $string 原字符串

      * @param replacenum $int 替換次數

      * @return string 返回字符串

      */

      function keylinks($txt, $replacenum = '') {

      global $linkdatas;

      if ($linkdatas) {

      $word = $replacement = array();

      foreach ($linkdatas as $v) {

      $word1[] = '/(?!(

      $word2[] = $v[0];

      $replacement[] = '' . $v[0] . '';

      }

      if ($replacenum != '') {

      $txt = preg_replace($word1, $replacement, $txt, $replacenum);

      } else {

      $txt = str_replace($word2, $replacement, $txt);

      }

      }

      return $txt;

      }

    【PHP關聯鏈接添加的方法】相關文章:

    PHP關聯鏈接添加方法有哪些07-12

    PHP關聯鏈接如何添加07-10

    PHP如何關聯鏈接添加04-15

    dreamweaver添加超鏈接的方法04-05

    使用dreamweaver添加超鏈接的方法03-17

    Dreamweaver添加超鏈接的方法技巧02-21

    dreamweaver添加超鏈接的方法是什么05-31

    dreamweaver添加超鏈接的使用方法08-06

    通過php添加xml文檔內容的方法04-23

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人