Php getting argument using $_GET

Discussion in 'PHP' started by rekha, Oct 30, 2008.

  1. rekha

    rekha New Member

    Joined:
    Jan 17, 2008
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I have a php page where i am getting argument from another page.The argument contains values similar to "Repair & Maintenance".If i retrieve that argument using $_GET method i am getting only "Repair" as the value.I need the value to be "Repair & Maintenance".How can i get this.

    Regards
    Rekha
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,367
    Likes Received:
    386
    Trophy Points:
    83
    You submitted the thread as article and I have moved it to forums for discussion.
     
  3. pete_bisby

    pete_bisby New Member

    Joined:
    Nov 11, 2007
    Messages:
    48
    Likes Received:
    2
    Trophy Points:
    0
    Occupation:
    Software Developer/Analyst, PB
    Location:
    Manchester, England
    Home Page:
    http://www.pbworld.co.uk
    The ampersand is causing the break in the URL - PHP populates the $_GET array from the URL. Everything to the right of the question mark goes to the $_GET array, with each pair of key/values.
    E.g.
    http://someurl.com?field1=value1&field2=value2
    $_GET["field1"] = "value1"
    $_GET["field2"] = "value2"

    Now because you have an ampersand in the URL, PHP thinks it is a new variable, which is the reason why the second half is disappearning.

    The solution: encode the URL correctly - look at htmlentities(), htmlspecialchars() or urlencode()
     
  4. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Use urlencode

    PHP:
    $url "http://www.go4expert.com/index.php?value=".urlencode('Repair & Maintenance');
    //http://www.go4expert.com/index.php?value=Repair%20%26%20Maintenance
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice