Home >Backend Development >PHP Tutorial >dedecms keyword replacement plan

dedecms keyword replacement plan

little bottle
little bottleforward
2019-04-26 11:55:292602browse

This article mainly talks about the dedecms keyword replacement plan. First replace the long-tail keywords and then replace the main keywords according to the frequency. This article has certain reference value, and interested friends can learn about it.

Problem: When using the document keyword replacement function of dedecms, it will cause cross replacement

For example:

Long tail keyword 1: Men drink gold silk What are the benefits of golden chrysanthemum?

Long tail keyword 2: What are the benefits of drinking golden silk royal chrysanthemum?

Main keyword 3: golden silk royal chrysanthemum

Use the system In the default function, when replacing the main keyword, the "Golden Thread Royal Chrysanthemum" in the long-tail keyword that has been replaced above will also be replaced, thus destroying the original long-tail keyword anchor text.

Solution:

1. First replace the keyword to be replaced with something like:

Keyword 1: '
##0
##'
Keyword 2:'
##2
##'
Keyword 3:'
##3
##'
When performing the above replacement operation , we need to save the anchor text corresponding to the keyword, such as:

'

##0

##' --> Anchor text of keyword 1

'##1 ##' --> Anchor text of keyword 2
'

##2#####' --> Anchor text of keyword 3 ### after all replacements are completed , we will finally restore it. ###Here, we mainly modify: include/arc.archives.class.php file ###The modified part is as follows: ###
//高亮专用, 替换多次是可能不能达到最多次
function _highlight($string, $words, $result, $pre) {
    global $cfg_replace_num;
    //     if (version_compare(PHP_VERSION, '5.5.0', '>='))
    //     {
    //         $string = $string[0];
    //         $pre = $pre[0];
    //     }
    
    //修改 Start
    $replaced_array = array();
    $replaced_tiems = 0;
    //修改 End
    
    $string = str_replace('\"', '"', $string);
    if ($cfg_replace_num > 0) {
        foreach ($words as $key => $word) {
            if ($GLOBALS['replaced'][$word] == 1) {
                continue;
            }
            //修改 Start
            $replace_string = '#####' . $replaced_tiems . '#####';
            $replaced_array[$replace_string] = $result[$key];
            $string = preg_replace("#" . preg_quote($word) . "#", $replace_string, $string, $cfg_replace_num);
            $replaced_tiems+= 1;
            //修改  End
            //             $string = preg_replace("#".preg_quote($word)."#", $result[$key], $string, $cfg_replace_num);
            if (strpos($string, $word) !== FALSE) {
                $GLOBALS['replaced'][$word] = 1;
            }
        }
        //修改 Start
        foreach ($replaced_array as $k => $v) {
            $string = str_ireplace($k, $v, $string);
        }
        //修改  End

    } else {
        $string = str_replace($words, $result, $string);
    }
    return $pre . $string;
}
###Note: Here we need to modify the document keywords in the background The frequency, the default is to replace those with high frequency first, and replace those with low frequency later ######Related tutorials: ###PHP video tutorial#########

The above is the detailed content of dedecms keyword replacement plan. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete