$_GET[] is killing my & signs!

Discussion in 'PHP' started by Kerosene, Sep 30, 2007.

  1. #1
    I hope I can explain this problem clearly...

    I have a simple htaccess rewrite to change
    domain.com/apple
    to
    domain.com/index.php?s=apple

    Using echo $_GET['s'] results in apple, as it should.

    The Problem
    If there's a & symbol in the url, e.g:
    domain.com/apple+&+banana

    $_GET['s'] cuts off at the & sign, and only gives me 'apple'.

    I'm not sure if this is a PHP issue, or a problem with my htaccess file (pasted below). Any ideas?

    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule ^(.*)/?$ index.php?s=$1 [QSA,L]
    Code (markup):
     
    Kerosene, Sep 30, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    To pass the ampersand sign as value, you have to URL encode it.

    & = %26

    domain.com/apple+%26+banana
     
    nico_swd, Sep 30, 2007 IP
    Kerosene likes this.
  3. ziogas

    ziogas Peon

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    or you can pass url throw urlencode() function
     
    ziogas, Sep 30, 2007 IP
    Kerosene likes this.
  4. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #4
    Thanks guys - got it working with a combo of both. :)
     
    Kerosene, Sep 30, 2007 IP