Skip to content

Instantly share code, notes, and snippets.

@sasin91
Created April 24, 2018 10:12
Show Gist options
  • Save sasin91/39ada8655d08446c781b8d649ba5958e to your computer and use it in GitHub Desktop.
Save sasin91/39ada8655d08446c781b8d649ba5958e to your computer and use it in GitHub Desktop.
Incensitive string contains
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