SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    UK
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Highlighting search text

    Hi

    I couldn't see a function in the sticky at the top of the forum, so I will ask:

    Does anyone use a funtion to highlight search terms (if they have a search facility on their site).

    Basically, I would be sending the search terms from a form field into a results page. If there are results I would like the search terms to be highlighted. One problem that I could think while using "replace" is that capitalisation would not be maintained.

    Thanks to any help.

    Cheers

    Del

  2. #2
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Once you match the results you can replace your search term with a font tag wrapped around it like so:

    Code:
    search_text = "test"
    text_to_search = "This is a test to see the search text highlighted"
     
    response.write REPLACE(text_to_search, search_text, "<font color=""red"">" & search_text & "</font>")
    This will basically replace your search text with the same text highlighted in red.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    UK
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks thing

    I'll have a go at that. Will it work where thereare more than one search term?

    Cheers

    Del


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •