How can I change the "+" in the search string?

Discussion in 'PHP' started by dalv, Jan 4, 2006.

  1. #1
    Hi guys,

    Do you know how I can change the "+" to "-" in the search string (osCommerce).

    Example:

    http://example.com/search_result.php?keywords=asd+asd

    should look:

    http://example.com/search_result.php?keywords=asd-asd

    How can I do that?

    I think there are two functions that could be related to the problem...but I am not a programmer, so I need help:

      function tep_sanitize_string($string) {
        $string = ereg_replace(' +', ' ', trim($string));
    
        return preg_replace("/[<>]/", '_', $string);
      }
    
    
    // Break up $search_str on whitespace; quoted string will be reconstructed later
        $pieces = split('[[:space:]]+', $search_str);
        $objects = array();
        $tmpstring = '';
        $flag = '';
    
        for ($k=0; $k<count($pieces); $k++) {
          while (substr($pieces[$k], 0, 1) == '(') {
            $objects[] = '(';
            if (strlen($pieces[$k]) > 1) {
              $pieces[$k] = substr($pieces[$k], 1);
            } else {
              $pieces[$k] = '';
            }
          }
    
          $post_objects = array();
    
          while (substr($pieces[$k], -1) == ')')  {
            $post_objects[] = ')';
            if (strlen($pieces[$k]) > 1) {
              $pieces[$k] = substr($pieces[$k], 0, -1);
            } else {
              $pieces[$k] = '';
            }
          }
    PHP:
     
    dalv, Jan 4, 2006 IP
  2. cytech

    cytech Guest

    Messages:
    62
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hey,

    Browsers normaly make added keywords with a "+" symbol.

    So you would need to do this when the user submits the form, you can use php but might be quicker to just use a small javascript function.

    If you can post the "search form" I can do it for ya.
     
    cytech, Jan 6, 2006 IP
  3. ctdp

    ctdp Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you use:

    $new_string=str_replace("+","-",$QUERY_STRING);

    Would creata the string "keywords=asd-asd". Using either the str_replace function or the ereg_replace function works. The ereg_replace function is the POSIX compliant version of the function.
     
    ctdp, Jan 6, 2006 IP
  4. dalv

    dalv Well-Known Member

    Messages:
    130
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    123
    #4
    Thanks, guys!

    ctdp, that did the trick!
     
    dalv, Jan 7, 2006 IP