By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,373 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,373 IT Pros & Developers. It's quick & easy.

how to highlight search terms

P: n/a

Commonly done, eg. you enter a word in a search engine and when a
hit-page comes up the search word(s) are highlighted.

I'm doing a fulltext search that works well but I've tried a few
"packaged scripts" and haven't got one to work yet. I'm looking for
straightforward understandable way to do this on my MYSQL/PHP pages.

Thanks,
Lee
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
leegold2 wrote:

Commonly done, eg. you enter a word in a search engine and when a
hit-page comes up the search word(s) are highlighted.

I'm doing a fulltext search that works well but I've tried a few
"packaged scripts" and haven't got one to work yet. I'm looking for
straightforward understandable way to do this on my MYSQL/PHP pages.

Thanks,
Lee


To Add: Just to make clear i'm looking for something I can add to my
existing PHP code that does the mysql fulltext search - all works fine.
I want to *add* the hiliting feature. Thanks
Jul 17 '05 #2

P: n/a
On Thu, 14 Oct 2004 00:50:46 GMT, leegold2 <le*****@nospam.net> wrote:
leegold2 wrote:

Commonly done, eg. you enter a word in a search engine and when a
hit-page comes up the search word(s) are highlighted.

I'm doing a fulltext search that works well but I've tried a few
"packaged scripts" and haven't got one to work yet. I'm looking for
straightforward understandable way to do this on my MYSQL/PHP pages.

Thanks,
Lee


To Add: Just to make clear i'm looking for something I can add to my
existing PHP code that does the mysql fulltext search - all works fine.
I want to *add* the hiliting feature. Thanks


This piece from ALA should help.
http://www.alistapart.com/articles/searchhighlight/

Enjoy!

Jul 17 '05 #3

P: n/a
leegold2 <le*****@nospam.net> wrote in message news:<G3kbd.823$WO1.510@trnddc03>...
leegold2 wrote:

Commonly done, eg. you enter a word in a search engine and when a
hit-page comes up the search word(s) are highlighted.

I'm doing a fulltext search that works well but I've tried a few
"packaged scripts" and haven't got one to work yet. I'm looking for
straightforward understandable way to do this on my MYSQL/PHP pages.

Thanks,
Lee


To Add: Just to make clear i'm looking for something I can add to my
existing PHP code that does the mysql fulltext search - all works fine.
I want to *add* the hiliting feature. Thanks


If you pass the search term to the page in the url, you could then use
str_replace to replace all instances of the search term. For example:

$output = str_replace($_GET[searchterm],"<font
color=red>".$_GET[searchterm]."</font>",$output);

I'd imagine this'd take up quite a bit of power and take a while to do
on big pages.
Jul 17 '05 #4

P: n/a
> Commonly done, eg. you enter a word in a search engine and when a
hit-page comes up the search word(s) are highlighted.

I'm doing a fulltext search that works well but I've tried a few
"packaged scripts" and haven't got one to work yet. I'm looking for
straightforward understandable way to do this on my MYSQL/PHP pages.


Does your search engine return the "coordinates" or the places of
discovery for your search patterns?
Can you iterate through a list where any markup can be added for the
highlighting?
Jul 17 '05 #5

P: n/a
"Psythor" wrote:
leegold2 <le*****@nospam.net> wrote in message
news:<G3kbd.823$WO1.510@trnddc03>...
leegold2 wrote:

Commonly done, eg. you enter a word in a search engine and when a hit-page comes up the search word(s) are highlighted.

Iím doing a fulltext search that works well but Iíve tried a few "packaged scripts" and havenít got one to work yet. Iím looking for straightforward understandable way to do this on my MYSQL/PHP pages.
Thanks,
Lee
To Add: Just to make clear iím looking for something I can

add to my
existing PHP code that does the mysql fulltext search - all works

fine.
I want to *add* the hiliting feature. Thanks


If you pass the search term to the page in the url, you could then

use str_replace to replace all instances of the search term. For example:
$output = str_replace($_GET[searchterm],"<font
color=red>".$_GET[searchterm]."</font>",$output);

Iíd imagine thisíd take up quite a bit of power and take a
while to do
on big pages.


This is exactly how phpbb works. Go to phpbb.com, go to forums, and
search for a term. You will see the term carried in the Query String,
and it is highlighted in the text. Actually php is very fast, and I
would not worry about performance --- takes a lot more resources to
load huge text index, than highlight a few words --at least 1000 to 1
in difference.

Come to think of it, download phpbb, and see how they do it.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-highligh...ict160305.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=539437
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.