cleanse_string()

Parameters

ColumnTypeDefaultDescription
$string
$preserve_separators
$preserve_hyphen false
$is_html false

Location

include/search_functions.php lines 2203 to 2248

Definition

 
function cleanse_string($string$preserve_separators$preserve_hyphen false$is_html false)
{
    
# Removes characters from a string prior to keyword splitting, for example full stops
    # Also makes the string lower case ready for indexing.
    
global $config_separators;
    
$separators $config_separators;

    
// Replace some HTML entities with empty space
    // Most of them should already be in $config_separators
    // but others, like ­ don't have an actual character that we can copy and paste
    // to $config_separators
    
$string htmlentities($stringENT_QUOTES ENT_SUBSTITUTE'UTF-8');
    
$string str_replace(' '' '$string);
    
$string str_replace('­'' '$string);
    
$string str_replace('‘'' '$string);
    
$string str_replace('’'' '$string);
    
$string str_replace('“'' '$string);
    
$string str_replace('”'' '$string);
    
$string str_replace('–'' '$string);

    
// Revert the htmlentities as otherwise we lose ability to identify certain text e.g. diacritics
    
$string html_entity_decode($stringENT_QUOTES'UTF-8');

    if (
        
$preserve_hyphen
        
&& (substr($string01) == "-" || strpos($string" -") !== false/*support minus as first character for simple NOT searches */
        
&& strpos($string" - ") === false
    
) {
        
# Preserve hyphen - used when NOT indexing so we know which keywords to omit from the search.
        
$separators array_diff($separators, array("-")); # Remove hyphen from separator array.
    
}
    if (
substr($string01) == "!" && strpos(substr($string1), "!") === false) {
            
// If we have the exclamation mark configured as a config separator but we are doing a special search we don't want to remove it
            
$separators array_diff($separators, array("!"));
    }

    if (
$preserve_separators) {
            return 
mb_strtolower(trim_spaces(str_replace($separators" "$string)), 'UTF-8');
    } else {
            
# Also strip out the separators used when specifying multiple field/keyword pairs (comma and colon)
            
$s $separators;
            
$s[] = ",";
            
$s[] = ":";
            return 
mb_strtolower(trim_spaces(str_replace($s" "$string)), 'UTF-8');
    }
}

This article was last updated 19th July 2025 21:35 Europe/London time based on the source file dated 17th July 2025 10:05 Europe/London time.