Special character (+) gets lost when transmitted as GET parameter

Posted on 2006-03-31
Last Modified: 2006-11-18

I have to process URLs having + characters and blanks in their GET parameter. Unfortunately, PHP is replacing the + characters by blanks. By the way, I access the GET parameters using $_GET[parameter].

Is there a way to prevent PHP from converting + characters in a URL to blanks?

Thanks a lot.
Question by:MichelLSZ
    LVL 16

    Accepted Solution


    Author Comment

    Does it mean that there is only the way to use urlencode() and urldecode() for every sent or received GET-Parameter?
    At least for preperation of references, like:

    echo "<a href=\"test.php?id=" . urlencode($id) . "\">";

    or when using JavaScript:

    location.href="test.php?id=" + encodeURIComponent(id);

    LVL 16

    Expert Comment

    urencode as u've seen in php manual, converts special characters by % and two hex digits. If it is vital for you to get all the special characters in your GET, then u got to use URL encode. but if u r planning to use GET with "id" or "pageNum" or numrical stuff like that, your don't have to use it !!!

    Author Comment

    Since I have + characters in my GET parameters I need to use urlencode(). Otherwise they are lost.

    Thanks a lot for your help.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now