Trying to Remove ' Apostrophe in Search

Discussion in 'PHP' started by seebeyond, Sep 22, 2008.

  1. #1
    Hi everyone, does anyone know how i can get my search on my site to ignore ' apostrophes?

    ie.

    cat's = cats

    i need this cause my db search is case sensitive and its not show search results of products with an ' in it. any help would be great. Thanks again
     
    seebeyond, Sep 22, 2008 IP
  2. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?
    $string = "cat's";
    str_replace("'", "", $string);
    //$string is now cats
    ?>
    PHP:
     
    zerxer, Sep 22, 2008 IP
  3. seebeyond

    seebeyond Peon

    Messages:
    76
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    zerxer will that code work for all apostrophes? I need it to basically omit all apostrophes when people type it in my search box. Thanks again.
     
    seebeyond, Sep 22, 2008 IP
  4. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #4
    The code is incorrect.

    Correct version:
    <?
    $string = "cat's";
    $string = str_replace("'", "", $string);
    //$string is now cats
    ?>
    PHP:
    Jay
     
    jayshah, Sep 22, 2008 IP
  5. seebeyond

    seebeyond Peon

    Messages:
    76
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks jay. won't this code work just for the word cat's?
     
    seebeyond, Sep 22, 2008 IP
  6. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #6
    Yes, but it's just an example.

    If you put
    $string = $THE_REAL_SEARCH_VARIABLE;
    PHP:
    Then it will work for whatever is searched.

    Jay
     
    jayshah, Sep 22, 2008 IP
  7. seebeyond

    seebeyond Peon

    Messages:
    76
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thanks jay im still learning i'm new to php =] you guys are the best
     
    seebeyond, Sep 22, 2008 IP
  8. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #8
    No problem. If you want the code tweaking a bit, just post what your current code looks like and I'm sure I, or someone else, will lend a hand.

    Jay
     
    jayshah, Sep 22, 2008 IP
  9. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Whoops, I forgot to re-set the string, huh. Clumsy. Thanks. :p
     
    zerxer, Sep 22, 2008 IP