At 11:13 AM -0500 3/18/02, Frank Sweetser wrote:
>I'm building a page that will have a bunch of nodes.  Each node has a block
>of text.  What I'd like to be able to do is search within that block of
>text for a given list of words, and for each word that's found, turn it into
>a hyperlink, unless it's a) part of an html tag or b) already part of a
>link.

Well, I'm not sure if this is what you are looking for, but...

Use EmbperlObject.  In the template build your search terms and
then do something like the following:

        Execute({inputfile => '*', output => \$output, options => 512+16});
        $search = '';
        foreach $arg (split(/\s+/, $query)) {
            $search .= quotemeta($arg) . '|';
        }
        chop($search);
        # Match the search pattern as long as it isn't followed by a >, unless
        # we hit a < first.  That should keep it out of tags.
        $output =~ s,\b($search)(?![^<]*>),<font color="#FF0000">\1</font>,ig;
        my $oescmode = $escmode;
        $escmode = 0;
        print OUT "<b>Searching for " . $query . "</b><br>\n";
        print OUT $output;
        $escmode = $oescmode;

In this particular case, I'm doing something slightly different.  I want to flag the 
results of a search, but the concept is the same.

Here's an example of the output:

http://commons.somewhere.com/buzz/1997/PrivacyDistribution.html?Search=privacy+cookies


-- 

Kee Hinckley - Somewhere.Com, LLC
http://consulting.somewhere.com/
[EMAIL PROTECTED]

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to