Rated an average of 0 stars by 0 people

String Contains

Script Details:
Added on February 3, 2011 by Zhay. Last modified February 3, 2011.
Zhay accreditted the script to himself.

Description:
Determines whether or not a string contains another string.

Tags: contains, string, substr, substring

Instructions:
<?php
if (str_contains('I love PHPShare', 'love'))
{
echo 'You are awesome';
}
?>

Code:

<?php
# Snippet from PHP Share: http://www.phpshare.org

function str_contains($haystack$needle$caseInsensitive false)
{
    if (
$caseInsensitive === true)
    {
        
$haystack strtolower($haystack);
        
$needle strtolower($needle);
    }
    
    if (
strpos($haystack$needle) === false)
    {
        return 
false;
    }
    else
    {
        return 
true;
    }
}
?>

Review this PHP Script:

Rating:

Comments:


Login

User:
Pass:

Register

Not a member? Register today and receive the many free benefits of being a member!

Advertisements