Skip to content

Instantly share code, notes, and snippets.

@gdarko
Last active May 2, 2024 02:43
Show Gist options
  • Save gdarko/5dbcf96dccb2a3eece6c10d084d008af to your computer and use it in GitHub Desktop.
Save gdarko/5dbcf96dccb2a3eece6c10d084d008af to your computer and use it in GitHub Desktop.
str_contains() was introduced in PHP8. This is a polyfill for PHP7 or lower.
<?php
if (!function_exists('str_contains')) {
/**
* Check if substring is contained in string
*
* @param $haystack
* @param $needle
*
* @return bool
*/
function str_contains($haystack, $needle)
{
return (strpos($haystack, $needle) !== false);
}
}
@dnaldoog
Copy link

dnaldoog commented May 2, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment