Make search accent-insensitive so Sondervig matches Søndervig
This commit is contained in:
parent
efcf87d00c
commit
62156ed946
2 changed files with 38 additions and 4 deletions
21
index.php
21
index.php
|
|
@ -7,12 +7,29 @@ if (!is_dir(__DIR__ . "/cache")) mkdir(__DIR__ . "/cache", 0775, true);
|
|||
function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, "UTF-8"); }
|
||||
function nice_title($s){ return trim(ucwords(str_replace(['_','-'], ' ', (string)$s))); }
|
||||
function lower_text($s){ return function_exists('mb_strtolower') ? mb_strtolower((string)$s, 'UTF-8') : strtolower((string)$s); }
|
||||
function fold_text($s){
|
||||
$s = strtr((string)$s, [
|
||||
'æ'=>'ae','Æ'=>'ae','ø'=>'o','Ø'=>'o','å'=>'aa','Å'=>'aa',
|
||||
'ä'=>'ae','Ä'=>'ae','ö'=>'oe','Ö'=>'oe','ü'=>'ue','Ü'=>'ue','ß'=>'ss','ẞ'=>'ss',
|
||||
'č'=>'c','Č'=>'c','ć'=>'c','Ć'=>'c','ž'=>'z','Ž'=>'z','š'=>'s','Š'=>'s','đ'=>'d','Đ'=>'d',
|
||||
]);
|
||||
if (function_exists('iconv')) {
|
||||
$x = @iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $s);
|
||||
if ($x !== false) $s = $x;
|
||||
}
|
||||
$s = lower_text($s);
|
||||
return preg_replace('/[^a-z0-9]+/', ' ', $s) ?? '';
|
||||
}
|
||||
function ci_contains($haystack, $needle){
|
||||
$haystack = (string)$haystack;
|
||||
$needle = (string)$needle;
|
||||
if ($needle === '') return true;
|
||||
if (function_exists('mb_stripos')) return mb_stripos($haystack, $needle, 0, 'UTF-8') !== false;
|
||||
return strpos(lower_text($haystack), lower_text($needle)) !== false;
|
||||
if (function_exists('mb_stripos') && mb_stripos($haystack, $needle, 0, 'UTF-8') !== false) return true;
|
||||
if (strpos(lower_text($haystack), lower_text($needle)) !== false) return true;
|
||||
$foldHay = fold_text($haystack);
|
||||
$foldNeedle = trim(fold_text($needle));
|
||||
if ($foldNeedle === '') return false;
|
||||
return strpos($foldHay, $foldNeedle) !== false;
|
||||
}
|
||||
function keep_non_empty(array $params): array { return array_filter($params, fn($v)=>$v !== '' && $v !== null); }
|
||||
function query_url(array $params): string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue