Jump to content

strpos with similar to REGEXP?


Mctittles

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:

[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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.