SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast dave_merwin's Avatar
    Join Date
    Apr 2003
    Location
    Eugene, OR
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Swap a charachter in a string in a variable from $_GET

    I am building a site search. This search gets a variable from a form using $_GET and passes it to the script for processing.

    Before anyone asks, I can NOT use FULLTEXT. MySQL 3.23 and I need to search for words with less than 3 characters.

    I have built it with LIKE and it works great for one word. Does what I need and preforms real fast.

    The problem comes when I try to search for a string that has multiple words. If I search for "Jack Jill" the value of $_GET becomes "Jack+Jill". So, naturally when I pass this to the db query my results are none.

    How do I remove the "+" and replace it with " "? My reasoning is that I want to seach the $_GET variable and find the "+" and replace it with " ".

    Logic:
    1. $search = $_GET['search'];
    2. If "+" then replace with " " for each occurance
    3. Return $search

    I am totally cool with being completely off. Please let me know what best practice might be. Again, I can NOT use FULLTEXT. MySQL 3.23 and I need to search for words with less than 3 characters.
    Dave Merwin

  2. #2
    SitePoint Evangelist
    Join Date
    May 2004
    Location
    Germany
    Posts
    550
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $search str_replace('+'' '$_GET['search']); 
    You could also replace the + with %, then you also get a result if the text is sth like "Jack and Jill.."

    hth

  3. #3
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dave_merwin
    The problem comes when I try to search for a string that has multiple words. If I search for "Jack Jill" the value of $_GET becomes "Jack+Jill". So, naturally when I pass this to the db query my results are none.
    Hmm, it's a bit strange. Normally php does this for you, i.e. if you pass "x=Jack+Jill" to the script, you should become "Jack Jill" in $_GET array. Care to post more code?


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
  •