Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<cf_highlight> issues

Status
Not open for further replies.

8ginga8

Programmer
Dec 14, 2004
54
CA
not sure if anyone can help me, but I would reall apriciate it if you could. I downloaded this custom tag from and it is not very long code. It seems to work fine except that it will only highlight the last word in the document, and not all instances of the word.

This is the code for the custom tag:

<cfparam name="attributes.words" default="test,is">
<cfparam name="attributes.delimeter" default=",">
<cfparam name="attributes.prefix" default="<b>">
<cfparam name="attributes.suffix" default="</b>">
<cfscript>
for (i=1;i LTE ListLen(attributes.words, attributes.delimeter);i=i+1) {
if (thistag.ExecutionMode IS "End") {
thisTag.GeneratedContent = ReReplaceNoCase(thisTag.GeneratedContent, "(.*)(#ListGetAt(attributes.words, i, attributes.delimeter)#)(.*)", "\1#attributes.prefix#\2#attributes.suffix#\3", "ALL");
}
}
</cfscript>

and this is the code on the page that has the tag on it:
<cfoutput>
<cfparam name="url.search" default="">
<cfset keywords = "#url.search#">
<cf_highlight words = "#keywords#">

<div class="heading">#get_text.heading#</div><BR>
#get_text.textarea#</cf_highlight></cfoutput>
 
With some modification.. This code from faq232-1167 should help you a lot. I used it on a few search engines that I've written and its nice stuff.

Code:
<cfset keyword = FORM.keyword>
<cfset oldResults = VARIABLES.results>
<cfset newResults = REReplaceNoCase(VARIABLES.oldResults, "(([^A-Za-z])(#Trim(VARIABLES.keyword)#)([^A-Za-z]))", "\2<b  style='background=color:yellow'>\3</b>\4", "ALL")>
<cfif Left(VARIABLES.newResults, Len(Trim(VARIABLES.keyword))) IS Trim(VARIABLES.keyword)>
    <cfset newResults = REReplaceNoCase(VARIABLES.newResults, "((#Trim(VARIABLES.keyword)#)([^A-Za-z]))", "<b style='background-color:yellow'>\2</b>\3", "ONE")>
</cfif>

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top