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 250 views
1 answer 130 views
1 answer 146 views
1 answer 125 views
1 answer 171 views
...