Jump to content


This topic is now archived and is closed to further replies.


strpos with similar to REGEXP?

Recommended Posts

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 [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?



Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.