URL Decoding
Decodes URL-encoded string
function HexadecimalToDecimal($hex) {
$hex = strtoupper($hex);
$hexLength = strlen($hex);
$dec = 0.0;
for ($i = 0; $i < $hexLength; $i++)
{
$b = ord($hex[$i]);
if ($b >= 48 && $b <= 57)
$b -= 48;
else if ($b >= 65 && $b <= 70)
$b -= 55;
$dec += $b * pow(16, (($hexLength - $i) - 1));
}
return (int)$dec;
}
function DecodeURL($data, $count) {
$j = 0;
for ($i = 0; $i < $count; $i++, $j++)
{
if ($data[$i] == '%')
{
$h = $data[$i + 1] . $data[$i + 2];
$result[$j] = chr(HexadecimalToDecimal($h));
$i += 2;
}
else
{
$result[$j] = $data[$i];
}
}
return implode("", $result);
}
Example
$data = "jdfgsdhfsdfsd%206445dsfsd7fg%2F%2A%2F%2Bbfjsdgf%25%24%5E";
$value = DecodeURL($data, strlen($data));
Output
jdfgsdhfsdfsd 6445dsfsd7fg/*/+bfjsdgf%$^