PHP проверяет, содержит ли строка слово
$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
echo "My string contains Bob";
}
Grepper
$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
echo "My string contains Bob";
}
$a = 'How are you?';
if (strpos($a, 'are') !== false) {
echo 'true';
}
<?php
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}
?>
phpCopy<?php
$mystring = "This is a PHP program.";
if (strpos($mystring, "program.") !== false) {
echo("True");
}
?>
phpCopy<?php
$mystring = "This is a php program.";
$search = "a";
if(preg_match("/{$search}/i", $mystring)) {
echo "True"; } else {
echo("False");
}
?>
$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
echo "My string contains Bob";
}