$string = 'The lazy fox jumped over the fence';
if (str_contains($string, 'lazy')) {
echo "The string 'lazy' was found in the string
";
}
$a = 'How are you?';
if (strpos($a, 'are') !== false) {
echo 'true';
}
$str = 'Hello World!';
if (strpos($str, 'World') !== false) {
echo 'true';
}
if (strpos($haystack,$needle) !== false) {
echo "$haystack contains $needle";
}
if (str_contains('How are you', 'are')) {
echo 'true';
}
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
phpCopy<?php
$mystring = "This is a PHP program.";
if (strpos($mystring, "program.") !== false) {
echo("True");
}
?>
if (strpos($a, 'are') !== false) {
echo 'true';
}
phpCopy<?php
$mystring = "This is a php program.";
$search = "a";
if(preg_match("/{$search}/i", $mystring)) {
echo "True"; } else {
echo("False");
}
?>
str_contains(string $haystack , string $needle);
phpCopy<?php
$mystring = "This is a PHP program.";
if (strpos($mystring, "PHP", 13) !== false) {
echo("True");
} else {
echo("False");
}
?>