php check if string contains
snippet in php

php check if string contains word

user4693

$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
    echo "My string contains Bob";
}

php find if string contains

user8973

if (strpos($string, 'substring') !== false) {
	// do stuff 
}

How do I check if a string contains a specific word?

user5993

$a = 'Hello world?';

if (strpos($a, 'Hello') !== false) { //PAY ATTENTION TO !==, not !=
    echo 'true';
}
if (stripos($a, 'HELLO') !== false) { //Case insensitive
    echo 'true';
}

php find if substring is in string

user9641

$result = strpos("haystack", "needle");

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

php string contains

user8320

$mystring = 'abc';
$findme   = 'a';
$pos = strpos($mystring, $findme);

php check if string contains

user6541

// returns true if $needle is a substring of $haystack
function contains($haystack, $needle){
    return strpos($haystack, $needle) !== false;
}