Skip to content

Commit eed1ade

Browse files
committed
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.
1 parent 5874794 commit eed1ade

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

api/search.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@
3535

3636
function strcasestr($haystack, $needle) : bool
3737
{
38-
if (strstr(strtolower($haystack), strtolower($needle)))
39-
return true;
40-
return false;
38+
$needle = strtolower($needle);
39+
$haystack = strtolower($haystack);
40+
$needle = preg_quote($needle, '/');
41+
$needle = str_replace('\*', '.*', $needle);
42+
$pattern = '/.*' . $needle . '.*' . '/';
43+
44+
return preg_match($pattern, $haystack) === 1;
4145
}
4246
foreach ($users as $u)
4347
{

0 commit comments

Comments
 (0)