Jump to content

search feature


RobertP

Recommended Posts

hello everyone ... i am here to see if you can help me with a small issue.

 

i am creating a search feature on my cms, and when someone searches for something, i want to cut the text... i don;t know how to explain it very well, but i will give an example.

 

Searching for 'text' ... 3 results found.

original text (987654321.text.123456789)
cut text (4321.text.1234)

 

i have been using substr, but it is not working out for me. ill show what i have been using.

 

if(strstr($page_content,$q)){
$strPos = strpos($page_content,$q);
$search_results[] = str_replace($q,'<span style="background-color:#FFFF00;color:#333333;">'.$q.'</span>',substr($page_content,$strPos-10,-10));
}

 

Link to comment
Share on other sites

 

if(strstr($page_content,$q)){
$strPos = strpos($page_content,$q);
$search_results[] = str_replace($q,'<span style="background-color:#FFFF00;color:#333333;">'.$q.'</span>',substr($page_content,$strPos-10,-10));
}

 

shouldn't your substr be using 10 as third parameter instead of -10?

actually, you should use substr($page_content,$strPos-10,strlen($q)+10); or something if you want to cut 10 before and 10 after the keyword and not counting with it

 

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.