Stefan Vogt
Stefan Vogt

Reputation: 1533

PHP: Encode decode point in url $_GET urldecode

I have: http://www.example.com/index.php?amount=15%252E8

In index.php:

    $test = $_GET['amount'];
    echo $test; 

    // Output: 15%2E8

But I don't need 15%2E8, I need 15.8

    $test = $_GET['amount'];
    $test = urldecode($test);
    echo $test; 
    
    //Output: 15.8

But in https://www.php.net/manual/en/function.urldecode.php they warn:

Warning: The superglobals $_GET and $_REQUEST are already decoded. Using urldecode() on an element in $_GET or $_REQUEST could have unexpected and dangerous results.

Why $_GET['amount'] does not get 15.8 ?!

Upvotes: 0

Views: 955

Answers (1)

deceze
deceze

Reputation: 522110

15%252E8 is the URL encoded version of "15%2E8".
15%2E8 is the URL encoded version of "15.8".
If you want "15.8", you should be sending 15%2E8 in the URL.

I.e. you're URL-encoding one time too many somewhere.

Upvotes: 4

Related Questions