This is driving me crazy. I’d like to know why in this PHP example code:
$str = '<p>Delivery: %DELIVERY-STAMP%</p>';
$str = rawurldecode($str);
echo $str;
The result is an empty string. But in this:
$str = '<p>Delivery: % DELIVERY-STAMP%</p>';
$str = rawurldecode($str);
echo $str;
The result result is
<p>Delivery: % DELIVERY-STAMP%</p>
The only difference is the extra space in % D. In other words, something really bad happens when the string “%D” is passed to rawurldecode() because I always get an empty string as result. This may be a bug? I couldn’t find any reference regarding “%D” in the documentation. I’m using PHP 5.4.2 In the actual code I cannot avoid running rawurldecode(). Many thanks in advance!
Because it’s interpreting
%DEas a literal character and decodes it to some character (222). From the docs:Well,
DandEare valid hex digits, so, it gets replaced.The real solution is to pass your string to
rawurlencode()first, then you can decode it withrawurldecode(), since in order to decode something, it needs to be encoded properly.The input string, properly encoded, looks like this: