Mctittles Posted April 30, 2006 Share Posted April 30, 2006 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:[code]fieldType='text' AND fieldContent REGEXP ('[[:<:]]".$searchData."[[:>:]]') ";[/code]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:[code]$findNumber=strpos(strtolower ($searchFound),strtolower($searchData));$startNumber= ($findNumber-50)>0 ? $findNumber-50 : 0;[/code]So next I use the $startNumber variable and do a [b]substr[/b] 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 [b]ereg[/b] 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 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.