• support@answerspoint.com

Check if string contains specific words?

432

Consider:

$a = 'How are you?';
if ($a contains 'are')
    echo 'true';

Suppose I have the code above, what is the correct way to write the statement if ($a contains 'are')?

1Answer


0

You can use the strpos function which is used to find the occurrence of one string inside other:

if (strpos($a,'are') !== false) {
    echo 'true';
}
  • answered 2 years ago
  • Sandy Hook

Your Answer

    Facebook Share