mardi 13 juillet 2021

How to check if any word found in string then [duplicate]

public static function likecheck($str, $searchTerm) {
    $searchTerm = strtolower($searchTerm);
    $str = strtolower($str);
    $pos = strpos($str, $searchTerm);
    if ($pos === false)
        return false;
    else
        return true;
}

it works fine to match any single word from $str

$found = App\Helper::likecheck('Developers are very good','very');
if($found){
    echo 'ok';
}

But I want to check by giving more words separated by commas, if any of the words is found then return true

LIKE:

$found = App\Helper::likecheck('Developers are very good','very, good, gentle');
      if($found){
        echo 'found';
    }

But it does not as it can check only one word.

Aucun commentaire:

Enregistrer un commentaire