The One
0
Q:

how to check if a string contains a substring in php

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

if (strpos($a, 'are') !== false) {
    echo 'true';
}
2
$result = strpos("haystack", "needle");

if ($result != false)
{
  // text found
}
3
if (strpos($haystack,$needle) !== false) {
    echo "$haystack contains $needle";
}
1
// returns true if $needle is a substring of $haystack
function contains($haystack, $needle){
    return strpos($haystack, $needle) !== false;
}
2

New to Communities?

Join the community