phpurldecode

How to decode a URL-encoded string?


I am working on a PayPal Subscription IPN. The custom variable I send to PayPal looks like this:

5|3

When PayPal send this back to me, it is urlencoded and looks like this:

5%7C3

If I want to use the explode function, can I do the following?

$custom = $_POST['custom'];
if(isset($custom))
{
    list($id_1, $id_2) = explode('|', $custom);
}

or like this?

$custom = $_POST['custom'];
if(isset($custom))
{
    list($id_1, $id_2) = explode('%7C', $custom);
}

How can I do this properly?


Solution

  • You can use this method

    $output = explode('|', urldecode($_POST['custom']));