If myString contains

<?php
$myString="abcde";
if($myString=="bc"){echo "yes";}
else{echo "no";}
?>

The code above will echo “no”.

The code below will produce a syntax error but it will show what I want.

<?php
$myString="a[COLOR="Blue"]bc[/COLOR]de";
if($myString [COLOR="Red"]contains[/COLOR] "[COLOR="blue"]bc[/COLOR]"){echo "yes";}
else{echo "no";}
?>

Take a look at [fphp]strpos[/fphp]

As ScallioXTX states, maybe [fphp]strpos/fphp can help; here’s a quick example.


<?php
$haystack = 'abcdefghijk';

if(false !== strpos($haystack, 'bc')){
  #found
}
?>

You could also create a quick function to make it a little easier.


<?php
function str_contains($haystack, $needle, $case_sensitive = false){
  return false !== call_user_func_array(
    (bool)$case_sensitive ? 'strpos' : 'stripos' ,
    array(
      $haystack,
      $needle
    )
  );
}

var_dump(
  str_contains('abcdefg', 'bC')
);
/* bool(true) */

var_dump(
  str_contains('abcdefg', 'bC', true)
);
/* bool(false) */
?>

another option

 
<?php
function isInString($myStr,$testStr,$caseSensitive) {
    if($caseSensitive) {
           return stripos($myStr,$testStr);
    } else {
          return strpos($myStr,$testStr);
    }
}
 
$myString ="abcde";
 
echo (isInString($myString,'bc',false) === false)? 'no' : 'yes';
 
?>

The code below which I wrote applying your code says no because it’s case-sensitive.
I like to make it say “yes”
How can I make it case-insensitive? for making it say"yes?"

<?php
$myString="abcde";
if(false !== strpos($myString, '[COLOR="Red"]B[/COLOR]c')){
echo "yes";}
else{echo "no";}
?>

Use stripos instead of strpos
The i stands for “case insensitive”

Thank you for making me to remember it.

Did you see the second block of code?