string contains php
snippet in php

php check if string contains word

user9367

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

php chech if string contains

user9020

$a = 'How are you?';

if (strpos($a, 'are') !== false) {
    echo 'true';
}

php find if string contains

user3712

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

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

user5500

$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

user5888

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

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

string contains php

user5851

$a = 'How are you?';

if (strpos($a, 'are') !== false) {
    echo 'true';
}