This question already has an answer here:
- How to find a whole word in a string in PHP without accidental matches? 1 answer
If I have a string containing the word Company and I wish to search for only full words, such as any, I encounter a problem using strpos(), as follows:
if (strpos($desc, $row['phrase']) !== false )
{
// action
}
This script will return TRUE because Company contains a substring: any which is unhelpful because the script needs to detect only full words.
The company is working
doesn't contain the word: any
but
Is there any change
does contain the word: "any". How may I edit a strpos function to search only full words, i.e. not part of them?
Thanks.