• support@answerspoint.com

Check if string contains specific words?

1804

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 8 years ago
  • Sandy Hook

Your Answer

    Facebook Share        
       
  • asked 9 years ago
  • viewed 1804 times
  • active 9 years ago

Best Rated Questions