Search a string within a string using PHP stristr function

arp14 PHP Tags: , 0

Use the function below to search a string within a string. This function is case-insensitive. Use stristr for case-insensitive and strstr for case-sensitive.

<?php
function search_string($string, $needle) {
    if (stristr($string, $needle) === false) {
        return false;
    }
    else {
        return true;
    }
}
?>

Leave a Reply

Note: Your email address will not be published. Required fields are marked *