织梦DEDECMS在PHP版本高于5.5的情况下无法使用关键词內链的解决方法

织梦DEDECMS在PHP版本高于5.5的情况下无法使用关键词內链的解决方法:

打开/include/arc.archives.class.php 找到 找到:

$body = @preg_replace_callback("#(^|>)([^<]+)(?=<|$)#sU", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body);

替换成:

global $cfg_replace_num;
if($cfg_replace_num > 0)
{
    $query = "SELECT * FROM #@__keywords WHERE rpurl<>'' ORDER BY rank DESC";
    $this->dsql->SetQuery($query);
    $this->dsql->Execute();
    while($row = $this->dsql->GetArray())
    {
        $key = trim($row['keyword']);
        $key_url=trim($row['rpurl']);
        $body = str_replace_limit($key, "<a href='$key_url' target='_blank'><u>$key</u></a>", $body, $cfg_replace_num);
    }

}
else
{
    $query = "SELECT * FROM #@__keywords WHERE rpurl<>'' ORDER BY rank DESC";
    $this->dsql->SetQuery($query);
    $this->dsql->Execute();
    while($row = $this->dsql->GetArray())
    {
        $key = trim($row['keyword']);
        $key_url=trim($row['rpurl']);
        $body = str_replace($key, "<a href='$key_url' target='_blank'><u>$key</u></a>", $body);
    }
}

搜索

//高亮专用

在它上面添加

//指定替换次数功能
function str_replace_limit($search, $replace, $subject, $limit)
{
    if(is_array($search))
    {
        foreach($search as $k=>$v)
        {
            $search[$k] = '`'. preg_quote($search[$k], '`'). '`';
        }
    }
    else
    {
        $search = '`'. preg_quote($search, '`'). '`';
    }
    return preg_replace($search, $replace, $subject, $limit);
}

 

THE END