Dan LaManna
Dan LaManna

Reputation: 3501

How do you find out if a word is present AS A WORD in a string?

Simply put, how do you find out if the 'the' is present in the following string: 'Well lately THEre seems to be much confusion between how to use THEy're, THEre, and THEir, I don't see what THE big deal is?'

The needle capitalized for exaggeration, just trying to figure out how to return the word the is found in the string, but if the string were filled with theres, they'res, and theirs, it wouldn't find it.

Thanks

Upvotes: 1

Views: 186

Answers (3)

niggles
niggles

Reputation: 1034

What about

/* if(stristr($haystack, 'the')){

   // do something

} */

doh didn't read the question closely enough.

Upvotes: 0

Max
Max

Reputation: 3439

search for ' the ' [extra space in the beginning and end]

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799510

Do a regex search for /\bthe\b/.

preg_match('/\bthe\b/', $text)

Upvotes: 7

Related Questions