0

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";
}
1
  • Thank you all for your comments and answers. it helped a lot. Commented Jun 30, 2013 at 0:20

1 Answer 1

3
$did_it_match = preg_match('/apple|cat/',$manywords);
Sign up to request clarification or add additional context in comments.

4 Comments

rofl I just noticed the question edit as well stackoverflow.com/posts/17385506/revisions though yes the original code pointed in that direction as well.
"the original code pointed in that direction" is the problem: The OP doesn't know what they want, so you can't use the direction of the code to point the right way.
Exactly, the echoed result and code contradicted each other, anyway one of your answers will have to be the right one.
I still have 2600 rep to go before I can see deleted answers :( You're a bit closer, glhf.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.