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
https://forums.phpfreaks.com/topic/248274-search-feature/
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
https://forums.phpfreaks.com/topic/248274-search-feature/#findComment-1275245
Share on other sites

Archived

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

×
×
  • 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.