From dc9f01ea48cee3fdcc5ac86957e62bdb3e17e6ba Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Wed, 2 Oct 2024 17:36:51 +0200 Subject: [PATCH] compare strings regardless of accents --- index.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index f920f57..3694408 100644 --- a/index.php +++ b/index.php @@ -21,6 +21,11 @@ $_SESSION['index'] = array_map(fn($value): string => str_replace('.md', '', $value), $files); } + function cleanstring($string) + { + return iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', strtolower($string)); + } + function downloadnote($path) { header('Content-disposition: attachment; filename=' . basename($path)); @@ -259,7 +264,7 @@ $content = file_get_contents($path . '.md'); if ( // param does not match content or title - (isset($_GET['search']) && !str_contains(strtolower($content), strtolower($param)) && !str_contains(strtolower($name), strtolower($param))) || + (isset($_GET['search']) && !str_contains(cleanstring($content), cleanstring($param)) && !str_contains(cleanstring($name), cleanstring($param))) || // param does not match tags (isset($_GET['tags']) && !preg_match('/tags:.*' . $param . '/i', $content)) ) @@ -289,9 +294,9 @@ echo ''; } } - else if (isset($_GET['search']) && str_contains(strtolower($content), strtolower($param))) + else if (isset($_GET['search']) && str_contains(cleanstring($content), cleanstring($param))) { - $pos = strpos(strtolower($content), strtolower($param)); + $pos = strpos(cleanstring($content), cleanstring($param)); echo ' ' . $param . substr($content, $pos + strlen($param), 42) . ''; } echo'';