• support@answerspoint.com

Check if string contains specific words?

1785

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 8 years ago
  • viewed 1785 times
  • active 8 years ago

Best Rated Questions