Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function contains($haystack, $needle, $caseSensitive = false) {
return $caseSensitive?
(strpos($haystack, $needle) === FALSE ? FALSE : TRUE):
(stripos($haystack, $needle) === FALSE ? FALSE : TRUE);
}
var_dump(contains('bare','are')); // Outputs : bool(true)
var_dump(contains('stare', 'are')); // Outputs : bool(true)
var_dump(contains('stare', 'Are')); // Outputs : bool(true)
var_dump(contains('stare', 'Are', true)); // Outputs : bool(false)
var_dump(contains('hair', 'are')); // Outputs : bool(false)
var_dump(contains('aren\'t', 'are')); // Outputs : bool(true)
var_dump(contains('Aren\'t', 'are')); // Outputs : bool(true)
var_dump(contains('Aren\'t', 'are', true)); // Outputs : bool(false)
var_dump(contains('aren\'t', 'Are')); // Outputs : bool(true)
var_dump(contains('aren\'t', 'Are', true)); // Outputs : bool(false)
var_dump(contains('broad', 'are')); // Outputs : bool(false)
var_dump(contains('border', 'are')); // Outputs : bool(false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.