Horje
php check if string contains word Code Example
php check if string contains word
$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
    echo "My string contains Bob";
}
check if string contains character php
// this method is new with PHP 8 and above
$haystack = "Damn, I wonder if this string contains a comma.";
if (str_contains($haystack, ",")) {
	echo "There is a comma!!";
}
Source: www.php.net
php find if substring is in string
$result = strpos("haystack", "needle");

if ($result != false)
{
  // text found
}
php contains substring

<?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";
}
?>

Source: www.php.net
How do I check if a string contains a specific word?
$a = 'Hello world?';

if (strpos($a, 'Hello') !== false) { //PAY ATTENTION TO !==, not !=
    echo 'true';
}
if (stripos($a, 'HELLO') !== false) { //Case insensitive
    echo 'true';
}
php check if string contains word
$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
    echo "My string contains Bob";
}




13

Related
laravel clear cache Code Example laravel clear cache Code Example
php string replace Code Example php string replace Code Example
php length of array Code Example php length of array Code Example
array count items Code Example array count items Code Example
check if array has value php Code Example check if array has value php Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10