php chech if string contains
snippet in php

php chech if string contains

user444

$a = 'How are you?';

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

php find if substring is in string

user6232

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

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

php check if string contains

user5506

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