Answers for "check if string has certain word"

PHP
1

if word exist in string

$a = 'How are you?';

if (strpos($a, 'are') !== false) {
    echo 'true';
}
Posted by: Guest on April-28-2020
0

check if a string contains a word

//By far the most accurate: VIA https://stackoverflow.com/a/25633879/7596555
function containsWord($str, $word)
{
    return !!preg_match('#\b' . preg_quote($word, '#') . '\b#i', $str);
}
Posted by: Guest on November-25-2021

Code answers related to "check if string has certain word"

Browse Popular Code Answers by Language