OsvaldoM Posted April 19, 2010 Share Posted April 19, 2010 Hello, i am using strpos for quick searches in large texts, everything was perfect till i found out strpos return the ocurrences for the string in-spite of the fact that is the whole word or just a part of it, and i need only to return exact matches... To exemplify what i am trying to say: say, i use strpos to look for "wonder" in a string, i would like it to return: I wonder if... I like Wonder bread... but i need strpos to ignore matches of words such as: Alice in Wonderland... She uses wonder-bra... I am thinking I could build a function to read the # of characters in the word, then run strpos() and check if there is whitespace around the word when found, if there is, return it, if not, ignore it. Though it seems to me there should be already a way to do this within strpos(), flags? or extra-values? Nothing in the manual talked about exact matches, and preg_match_all is not a very frendly function for newbies... so basically i am asking if i should continue with strpos() or better start looking for something else? Quote Link to comment Share on other sites More sharing options...
OsvaldoM Posted April 19, 2010 Author Share Posted April 19, 2010 After all, it seems preg_match is quite simple: i found this in the manual: if (preg_match("/\b$wordLW\b/i", $v)) { return $v; } $wordLW is the word i am looking for $v is the text or sentence to search the word in It runs a insensitive search for the word and only returns exact matches... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.