sorthighlights()

Description

Comparison function for sorting highlights by their length.

This function is used to sort keyword highlights for the `str_highlight` function.
It ensures that keywords are sorted based on their length, with shorter keywords
coming before longer ones. If the lengths are equal, it sorts them alphabetically.

This fixes an odd problem for str_highlight related to the order of keywords.

Parameters

ColumnTypeDefaultDescription
$a string The first string to compare.
$b string The second string to compare.

Return

int Returns 0 if lengths are equal, -1 if $a is shorter than $b, and 1 if $a is longer than $b.

Location

include/search_functions.php lines 2505 to 2511

Definition

 
function sorthighlights($a$b)
{
    if (
strlen($a) < strlen($b)) {
        return 
0;
    }
    return (
$a $b) ? -1;
}

This article was last updated 12th June 2025 21:35 Europe/London time based on the source file dated 4th June 2025 11:45 Europe/London time.