Justin k
Justin k

Reputation: 1104

php if a string contain two different characters

How can I see if a given string contatin multiple characters that I want to look for? for ex:

$manywords = "apple orange pineapple banana cat";
if (!(strstr($manywords, 'apple'||'cat')))
{
    echo "either word found";
}

is there a way I can use strstr function without having to write it twice as follows:

if (!((strstr($manywords, 'apple')||(strstr($manywords, 'cat')))
{
     echo "either word found";
}

Upvotes: 0

Views: 66

Answers (1)

000
000

Reputation: 27247

$did_it_match = preg_match('/apple|cat/',$manywords);

Upvotes: 3

Related Questions