contains php
snippet in php

php check if string contains word

user9112

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

if part of stringp ph

user4471

$a = 'How are you?';

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

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

user7299

$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

user3986

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

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

php string contains

user5113

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

contains php

user4950

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