php проверява дали низ дума
$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
echo "My string contains Bob";
}
php chech, ако низът съдържа
$a = 'How are you?';
if (strpos($a, 'are') !== false) {
echo 'true';
}
php намира, има ли подниз в низ
$result = strpos("haystack", "needle");
if ($result != false)
{
// text found
}
php намерете съдържа ли ред
if (strpos($string, 'substring') !== false) {
// do stuff
}
Как да се провери, дали ред на определена дума?
$a = 'Hello world?';
if (strpos($a, 'Hello') !== false) { //PAY ATTENTION TO !==, not !=
echo 'true';
}
if (stripos($a, 'HELLO') !== false) { //Case insensitive
echo 'true';
}
str_ включва php
<?php
$string = 'The lazy fox jumped over the fence';
if (str_contains($string, '')) {
echo "Checking the existence of an empty string will always return true";
}
if (str_contains($string, 'lazy')) {
echo "The string 'lazy' was found in the string\n";
}
if (str_contains($string, 'Lazy')) {
echo 'The string "Lazy" was found in the string';
} else {
echo '"Lazy" was not found because the case does not match';
}
# Checking the existence of the empty string will always return true
# The string 'lazy' was found in the string
# "Lazy" was not found because the case does not match
ред съдържа php
$a = 'How are you?';
if (strpos($a, 'are') !== false) {
echo 'true';
}
if (strpos($a, 'are') !== false) {
echo 'true';
}