This is how you could call it:

<cfoutput>
    <font style="font:13px Verdana;font-weight:bold">#highlight('Highlight some text here.','text')#</font>
</cfoutput>
<br /><br />

As you can see the characters 'text' are highlighted. The format of the string is not altered. You can use this script to
highlight your search results.
<br /><br />

<cfscript>
    function highlight(findIn,replaceThis) {
                        foundAt = FindNoCase(replaceThis, findIn);
                        endAt = FindNoCase(replaceThis, findIn) + len(replaceThis);
                        if(foundAt gt 0)
                        {        
                            findIn =Insert('</span>', findIn, endAt-1);
                            findIn =Insert('<span style="background-color:yellow">', findIn, foundAt-1);
                        }    
                        return findIn;
    }
</cfscript>

About This Tutorial
Author: Nebu Kadnezar
Skill Level: Intermediate 
 
 
 
Platforms Tested: CFMX7
Total Views: 89,565
Submission Date: May 01, 2006
Last Update Date: June 05, 2009
All Tutorials By This Autor: 2
Discuss This Tutorial
  • http://cflib.org/udf.cfm?ID=133 Works better, avoids a highlight word that might be contained in a html tag.

Advertisement


Website Designed and Developed by Pablo Varando.