]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blobdiff - api/search.php
Search: Make vaguely wildcard-y
[irc/unrealircd/unrealircd-webpanel.git] / 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)
 {