Jump to content


Photo

strpos with similar to REGEXP?


  • Please log in to reply
No replies to this topic

#1 Mctittles

Mctittles
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 30 April 2006 - 03:29 AM

Hello all. I'm doing a search for a web page that searches articles from the database. I've got the mySQL part going where $searchData comes from the FORM:

fieldType='text' AND fieldContent REGEXP  ('[[:<:]]".$searchData."[[:>:]]') ";

So I get back a result that only match the whole word of searchData. Next I would like to display an exerpt of the text surrounding the word found with the word(s) found in bold. I've tried this where $searchFound is the mySQL result:

$findNumber=strpos(strtolower ($searchFound),strtolower($searchData));
$startNumber= ($findNumber-50)>0 ? $findNumber-50 : 0;

So next I use the $startNumber variable and do a substr on it to display a little exerpt from the result found. The problem is although the mySQL will only return whole words, the strpos will match "the" with "them" and so on.

Although I'm not too familiar with it, I looked into using ereg a little and can't seem to find a use for it with what I'm doing because it only returns true or false and I need to know the location of the string found.

Any ideas?

Thanks.

-Shawn





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users