Is there a function that searches if a word exists in the text?

2

In PHP there is some função that does the verification of words in texts, example:

A camila morreu de diabete.

I want to create a function by looking for the word morreu , so after finding a if result, it looks something like this:

if (função == 'morreu') { echo 'OK'; } else { echo 'FAIL'; }

Is there a function?

    
asked by anonymous 09.10.2018 / 00:51

1 answer

3

You have strpos() . Or stripos() if you want to ignore the letters box. In some cases you may want to search for the end, perhaps per performance, with strrpos() .

These functions return false if the searched text is not in the full text, or returns the position of the first occurrence of the text if it is found. So you can test this, something like this:

if (strpos('A camila morreu de diabete', 'morreu') !== false) { echo 'OK'; } else { echo 'FAIL'; }
    
09.10.2018 / 01:02