xxxxxxxxxx
phpCopy<?php
$mystring = "This is a php program.";
$search = "a";
if(preg_match("/{$search}/i", $mystring)) {
echo "True"; } else {
echo("False");
}
?>
xxxxxxxxxx
$a = 'How are you?';
if (strpos($a, 'are') !== 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
private function findString($string, $subString): bool
{
if (str_contains($string, $subString)) {
return true;
}
return false;
}
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.";
if (strpos($mystring, "PHP", 13) !== false) {
echo("True");
} else {
echo("False");
}
?>
xxxxxxxxxx
string = "This is a sample string containing php"
if "php" in string:
print("The string contains 'php'")
else:
print("The string does not contain 'php'")