zero-perfoliate
zero-perfoliate

Author Topic: Searching Text For A String  (Read 146 times)

Offline aotearoa

  • New PHP Members
  • Posts: 1
  • Karma: +0/-0
Searching Text For A String
« on: August 16, 2010, 09:56:08 AM »
I am trying to make   a little script that allows a user to search for blocks of text within   strings.  The user enters data into form fields and he or she can enter   text into another form field (needle) to search the data fields   (haystack).  When the search string matches something in the data fields   the associated data fields are highlighted in a yellow background   color.
   
  Right now the search string is acting funny. When I enter a   search string I get no highlighting unless if the first character(s) of   the search string are the same as the first character(s) for the items.    For instance, If I search for the text "at" in the word "bat" I will   not get any yellow highlighting.  But I would get highlighting for "bat"   if I search for "ba."  How would I   change the code so that any data field is highlighted if the search   string exists anywhere in the text for the data field?
 
  Also, I figured out how to stop the form fields from being yellow if   they and the search field are empty/NULL, but I did this part in another   file (as an IF statement) and can't seem to get it to work in the   other file.  How would I make it do the highlighting if and only if   there is a search string in the search field (i. e. only highlighting   when the search field is not NULL/empty).
   
  The code from my 2 files is here...: http://www.pastie.org/1095526 , http://www.pastie.org/1095528
 
  Thanks very much to anyone who can help me.