Deanna,
I've made a few alterations to the highlight UDF which should work. It
basically uses recursion to call itself on each word of a comma delimitted
list (you should probably change this to make the delimiter an optional
parameter, I was just lazy). I've done a few basic tests and it seems to
work, but no garauntees.
One thing you need to watch out for when highlighting multiple keywords is
that if you have any keyword which is a substring of another keyword, you
may not get the correct results. There are workarouds for this, but it's
probably a pretty unlikely occurance depending on what you are using the
highlight function for. If it becomes a problem, I can tell you how I've
dealt with it in the past.
Here's the modified UDF....
function highLight(str, wordList) {
var front = "<span style=""background-color: yellow;"">";
var back = "</span>";
var matchCase = false;
//check for empty word list, this is the base condition for the recursion
if(ListLen(wordList) Lt 1)
return str;
else
word = ListFirst(wordList);
if(ArrayLen(arguments) GTE 3) front = arguments[3];
if(ArrayLen(arguments) GTE 4) back = arguments[4];
if(ArrayLen(arguments) GTE 5) matchCase = arguments[5];
if(Not matchCase)
CurTxt = REReplaceNoCase(str,"(#word#)","#front#\1#back#","ALL");
else
CurTxt = REReplace(str,"(#word#)","#front#\1#back#","ALL");
return Highlight(CurTxt, ListRest(wordList), front, back, matchCase);
}
Let me know if it works for you....
on a more personal note; I don't know if you remember me but I used to work
for UWEX in Wisplan. Say hi to Eric and Greg for me if they're still kicking
around there.
</rob>
-----Original Message-----
From: Deanna Schneider [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 09, 2002 2:18 PM
To: CF-Talk
Subject: udf help
Hi Folks,
I'm trying to modify Raymond Camden's highlight udf to allow for multiple
terms, and I'm not having a lot of luck. But, I've never written a udf,
so....
Here's where I'm at so far, basically, my thinking is that I have to loop
over the regular expression for each term passed in, yes? But, it's not
working - doesn't throw an error, but doesn't highlight anything either.
(Yes, I realize that only the Not matchase part would loop right now...one
piece at a time.)
function highLight(str,word) {
var front = "<span style=""background-color: yellow;"">";
var i = 0;
var back = "</span>";
var matchCase = false;
if(ArrayLen(arguments) GTE 3) front = arguments[3];
if(ArrayLen(arguments) GTE 4) back = arguments[4];
if(ArrayLen(arguments) GTE 5) matchCase = arguments[5];
if(NOT matchCase)
for(i=1; i lt listlen(word, " "); i = i + 1)
return REReplaceNoCase(str,"#listgetat(word,i)#","#front#\1#back#","ALL");
else return REReplace(str,"(#word#)","#front#\1#back#","ALL");
}
Deanna Schneider
Interactive Media Developer
[EMAIL PROTECTED]
______________________________________________________________________
Your ad could be here. Monies from ads go to support these lists and provide more
resources for the community. http://www.fusionauthority.com/ads.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists