How to check if strings contain another string in PHP

1 Answer

0 votes
function contain($str1, $str2) {
    return strpos($str1, $str2) !== false;
}
 
 

$str1 = "c# php c++ java c";
$str2 = "php";

if (contain($str1, $str2)) {
    echo "yes";
}
else {
    echo "no";
}




/*
run:

yes

*/

 



answered Dec 23, 2021 by avibootz

Related questions

2 answers 367 views
1 answer 203 views
1 answer 232 views
1 answer 194 views
1 answer 245 views
...