Skip to content

Instantly share code, notes, and snippets.

@AucT
Created December 11, 2022 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AucT/13a74e9fdc9cee8cfbae7e734387c725 to your computer and use it in GitHub Desktop.
Save AucT/13a74e9fdc9cee8cfbae7e734387c725 to your computer and use it in GitHub Desktop.
str_icontains and case-insensitive str_icontains
<?php
// Polyfill for PHP 4 - PHP 7, safe to utilize with PHP 8
if (!function_exists('str_contains')) {
function str_contains (string $haystack, string $needle)
{
return empty($needle) || strpos($haystack, $needle) !== false;
}
}
// case-insensitive str_icontains
if (!function_exists('str_icontains')) {
function str_icontains (string $haystack, string $needle)
{
return empty($needle) || stripos($haystack, $needle) !== false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment