Page 1 of 1
word in a text
Posted: Mon Jul 23, 2007 10:43 am
by pppswing
Hi,
I need to build a function that send me 'true' if a word is written in a text.
I don't know what php function is the best, I think that preg_match is a bit heavy.
Do you know better alternatives? a string function?
Thanks

Posted: Mon Jul 23, 2007 11:08 am
by stereofrog
preg_match is ok for the job.

Posted: Mon Jul 23, 2007 11:08 am
by malcolmboston
for simplicitys sake i highly recommend
strstr
thought i'd also mention if you just needed a simple BOOL answer as to whether needle is in haystack:
str_pos
Posted: Mon Jul 23, 2007 11:23 am
by stereofrog
neither of them is able to tell if a word is in the string
Posted: Mon Jul 23, 2007 12:49 pm
by Chalks
Code: Select all
preg_match("/start/i", $stringToCheck, $arrayToHoldMatches);
That will work just fine.
Or:
What malcolmboston said is true. strstr() is _very_ easy to use, so is strpos(). Just read the links he gave you.
Posted: Mon Jul 23, 2007 2:16 pm
by superdezign
stereofrog wrote:neither of them is able to tell if a word is in the string
What? I hope you meant to say that BOTH of them are able to tell if a word is in a string, but not able to differentiate between an actual separated word with boundaries and just a portion of a word with the same characters.