Skip to content

搜索无法高亮,function_search.php中两行代码写反 #9

@KKRainbow

Description

@KKRainbow

55,56行代码应该互换位置。

function bat_highlight($message, $words, $color = '#ff0000') {
    if(!empty($words)) {
        $highlightarray = explode(' ', $words);
        $sppos = strrpos($message, chr(0).chr(0).chr(0));
        if($sppos !== FALSE) {
            $specialextra = substr($message, $sppos + 3);
            $message = substr($message, 0, $sppos);
        }
        $message = preg_replace("/<highlight>(.*)<\/highlight>/siU", "<strong><font color=\"$color\">\\1</font></strong>", $message);
        $message = preg_replace_callback("/(^|>)([^<]+)(?=<|$)/sU", function($matches) use($highlightarray) { return highlight($matches[2], $highlightarray, $matches[1]); }, $message);
        if($sppos !== FALSE) {
            $message = $message.chr(0).chr(0).chr(0).$specialextra;
        }
    }
    return $message;
}
$message = preg_replace("/<highlight>(.*)<\/highlight>/siU", "<strong><font color=\"$color\">\\1</font></strong>", $message);
$message = preg_replace_callback("/(^|>)([^<]+)(?=<|$)/sU", function($matches) use($highlightarray) { return highlight($matches[2], $highlightarray, $matches[1]); }, $message);

改为

$message = preg_replace_callback("/(^|>)([^<]+)(?=<|$)/sU", function($matches) use($highlightarray) { return highlight($matches[2], $highlightarray, $matches[1]); }, $message);
$message = preg_replace("/<highlight>(.*)<\/highlight>/siU", "<strong><font color=\"$color\">\\1</font></strong>", $message);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions