From: Valerie Pond Date: Mon, 19 Aug 2024 01:57:43 +0000 (+0800) Subject: Search: Make vaguely wildcard-y X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/commitdiff_plain/eed1ade0e1c8b5340d9619c8fb6b4a08d230f3e9?ds=inline Search: Make vaguely wildcard-y You can use an asterisk `*` to represent "anything of any length" So `O*SAS` would match with `OVH SAS` Additionally, each end of your search query is treated like a wildcard/asterisk So `VH*A` would still match `OVH SAS` These are just examples to give an idea. --- diff --git a/api/search.php b/api/search.php index c54d7f8..9b78452 100644 --- a/api/search.php +++ b/api/search.php @@ -35,9 +35,13 @@ $search_results = [ function strcasestr($haystack, $needle) : bool { - if (strstr(strtolower($haystack), strtolower($needle))) - return true; - return false; + $needle = strtolower($needle); + $haystack = strtolower($haystack); + $needle = preg_quote($needle, '/'); + $needle = str_replace('\*', '.*', $needle); + $pattern = '/.*' . $needle . '.*' . '/'; + + return preg_match($pattern, $haystack) === 1; } foreach ($users as $u) {