Created
April 24, 2018 10:12
-
-
Save sasin91/39ada8655d08446c781b8d649ba5958e to your computer and use it in GitHub Desktop.
Incensitive string contains
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (! function_exists('istr_contains')) { | |
/** | |
* Insensitively check if given haystack contains anything like the given needle(s). | |
* | |
* @param string $haystack | |
* @param string[] $needles | |
* @return boolean | |
*/ | |
function istr_contains($haystack, $needles = []) | |
{ | |
// return str_contains(mb_str_lower($haystack), array_map('mb_str_lower', array_wrap($needles))); | |
foreach (array_wrap($needles) as $needle) { | |
if ($needle !== '' && mb_stripos($haystack, $needle) !== false) { | |
return true; | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment