I can't remove + from url

Discussion in 'PHP' started by MyVodaFone, Aug 16, 2010.

  1. #1
    For an example, if you where to search google for this phrase I can't remove + from url you end up in the address something like this /search?q=I+can't+remove+%2B+from+url. My question is, what is it that sends the +'s in between words and is it possible to remove them.

    Reason is, when I post a url /I cant remove its coming out as /I+cant+remove which is different right, although the page is the same.

    An example of usage would be say facebooks likes button. So does anybody know what I'm trying to say :) and if so, any ideas how to over come this ?
     
    MyVodaFone, Aug 16, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    + is added to represent space (to help distinguish a new word)

    Theirfore to remove you can do a simple str_replace replacing the + (plus) character with ' ' (space)
     
    danx10, Aug 16, 2010 IP
  3. jpratama

    jpratama Member

    Messages:
    31
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    The + is needed to concatenate between words which commonly separate with spaces. It should only happen in the query string (browser's address bar) and translate back to spaces normally. But if some reason it always exist you can remove it with php function string_replace. I hope I didn't misunderstood your your problem.
     
    jpratama, Aug 16, 2010 IP
  4. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #4
    Those are url encoding. If you visit this in your browser:
    http://www.google.com/search?q=lol lol
    Code (markup):
    It should interpret whitespace as %20
     
    Rainulf, Aug 16, 2010 IP
  5. Googl

    Googl Active Member

    Messages:
    509
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    75
    #5
    Since you're passing a query, you can escape it or replace the space character.
     
    Googl, Aug 17, 2010 IP
  6. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #6
    I was under the impression that having a +(plus) in the url was going to make a difference, to say example a facebook like button, but it turns out the + must be just ignored, however out of curiosity, how would I make it so that the + pluses don't appear in the url address bar. Is it str_replace on the value, but that doesn't show any pluses, or this is where I think it gets complicated my urls are .htaccess redirect.

    Options +FollowSymLinks
    
    RewriteEngine on
    
    RewriteBase /
    
    RewriteRule ^search([^/]+)_([^/]+)\.htm?$ index.php?dvd_search_type=$1&dvd_search=$2 [L]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?dvd_search_type=([^&]+)&dvd_search=([^&]+)\ HTTP/
    
    RewriteRule ^index\.php$ /search%1_%2\.htm? [R=301,L]
    Code (markup):
    Anyway thanks for all the replies... its not that important (now), so please don't waste too much time on this.
     
    MyVodaFone, Aug 17, 2010 IP