]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/commitdiff
Search: Make vaguely wildcard-y
authorValerie Pond <redacted>
Mon, 19 Aug 2024 01:57:43 +0000 (09:57 +0800)
committerValerie Pond <redacted>
Mon, 19 Aug 2024 01:57:43 +0000 (09:57 +0800)
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.

api/search.php

index c54d7f8259da11fb3a427d85076c0b7a7be6af64..9b78452e86728b221148c2cb895aca8049883e14 100644 (file)
@@ -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)
 {