How to highlight the keyword in search result

Helpdesk for my helpdesk software

Moderator: mkoch227

Post Reply
deserteagle369
Posts: 94
Joined: Wed Feb 29, 2012 2:00 am

How to highlight the keyword in search result

Post by deserteagle369 »

Script URL:
Version of script:
Hosting company:
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution:

Write your message below:

Highlight the keyword in kb suggestion or search result make it easy to read, how to do it?

Thanks,

Eagle
Eagle
Life is a journey.
deserteagle369
Posts: 94
Joined: Wed Feb 29, 2012 2:00 am

Re: How to highlight the keyword in search result

Post by deserteagle369 »

I added some lines to make it work for kb suggestion.

suggest_articles.php

in line 88 before echo '

add 4 lines:

Code: Select all

$high = $query;
$repl = '<span style="background-color:yellow">' . $high . '</span>';
$hightxt = str_ireplace($high, $repl, $txt);
$highsubject = str_ireplace($high,$repl,$article['subject']);
then change the line after echo '
from

Code: Select all

<a href="knowledgebase.php?article='.$article['id'].'&suggest=1" target="_blank">'.$article['subject'].'</a>
		    <br />'.$txt.'<br /><br />';
to

Code: Select all

<a href="knowledgebase.php?article='.$article['id'].'&suggest=1" target="_blank">'.$highsubject.'</a>
		    <br />'.$hightxt.'<br /><br />';
That's done.
Eagle
Life is a journey.
deserteagle369
Posts: 94
Joined: Wed Feb 29, 2012 2:00 am

Re: How to highlight the keyword in search result

Post by deserteagle369 »

it also work for kb search, alsmost same.
knowledgebase.php
line 240
after

Code: Select all

{
	            	$txt = substr(strip_tags($article['content']),0,$hesk_settings['kb_substrart']).'...';
	            }
add 4 lines

Code: Select all

$high = $query;
$repl = '<span style="background-color:yellow">' . $high . '</span>';
$hightxt = str_ireplace($high, $repl, $txt);
$highsubject = str_ireplace($high,$repl,$article['subject']);
then change the subject and txt just few lines after
from

Code: Select all

<td valign="top"><a href="knowledgebase.php?article='.$article['id'].'">'.$article['subject'].'</a></td>
to

Code: Select all

<td valign="top"><a href="knowledgebase.php?article='.$article['id'].'">'.$highsubject.'</a></td>
from

Code: Select all

<td><span class="article_list">'.$txt.'</span></td>
to

Code: Select all

<td><span class="article_list">'.$hightxt.'</span></td>
For the admin page, kb search is in knowledgebase_private.php, so you need change it also, then duplicate knowledgebase_private.php to knowledgebase.php again.

Eagle
Eagle
Life is a journey.
Klemen
Site Admin
Posts: 10145
Joined: Fri Feb 11, 2005 4:04 pm

Re: How to highlight the keyword in search result

Post by Klemen »

Thanks for sharing.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Post Reply