Add function stri_contains for case-insensitive, but intuitive

str_contains
This commit is contained in:
Joshua Ramon Enslin 2021-09-28 01:15:51 +02:00
parent a1e6d7773b
commit 245d161805
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -174,6 +174,39 @@ final class MD_STD {
}
/**
* Function checking if a string contains another in a case-insensitive way.
*
* @param string $haystack String to check.
* @param string $needle Potential start of $haystack.
*
* @return boolean
*/
public static function stri_contains(string $haystack, string $needle):bool {
if (stripos($haystack, $needle) === false) return false;
return true;
}
/**
* Function checking if a string contains any of a given set of strings in a
* case-insensitive way.
*
* @param string $haystack String to check.
* @param string[] $needles Potential values contained in haystack.
*
* @return boolean
*/
public static function stri_contains_any(string $haystack, array $needles):bool {
foreach ($needles as $needle) {
if (self::stri_contains($haystack, $needle) === true) return true;
}
return false;
}
/**
* Type-safe(r) wrapper around preg_replace.
*