xxxxxxxxxx
if (str_contains('How are you', 'are')) {
echo 'true';
}
xxxxxxxxxx
$string = 'The lazy fox jumped over the fence';
if (str_contains($string, 'lazy')) {
echo "The string 'lazy' was found in the string\n";
}
xxxxxxxxxx
$str = 'Hello World!';
if (strpos($str, 'World') !== false) {
echo 'true';
}
xxxxxxxxxx
phpCopy<?php
$mystring = "This is a PHP program.";
if (strpos($mystring, "program.") !== false) {
echo("True");
}
?>
xxxxxxxxxx
$string = "Hello World";
$substring = "World";
if (strpos($string, $substring) !== false) {
echo "The string contains the substring";
} else {
echo "The string does not contain the substring";
}
xxxxxxxxxx
$string = "This is a sample string.";
$substring = "sample";
// Case-insensitive search
if (strpos(strtolower($string), strtolower($substring)) !== false) {
echo "Substring found in the string.";
} else {
echo "Substring not found in the string.";
}
xxxxxxxxxx
phpCopy<?php
$mystring = "This is a php program.";
$search = "a";
if(preg_match("/{$search}/i", $mystring)) {
echo "True"; } else {
echo("False");
}
?>
xxxxxxxxxx
phpCopy<?php
$mystring = "This is a PHP program.";
if (strpos($mystring, "PHP", 13) !== false) {
echo("True");
} else {
echo("False");
}
?>