rawurldecode

(PHP 3, PHP 4, PHP 5)

rawurldecode -- Decode URL-encoded strings

Description

string rawurldecode ( string str )

Returns a string in which the sequences with percent (%) signs followed by two hex digits have been replaced with literal characters.

Пример 1. rawurldecode() example

<?php

echo rawurldecode('foo%20bar%40baz'); // foo bar@baz

?>

Замечание: rawurldecode() does not decode plus symbols ('+') into spaces. urldecode() does.

See also rawurlencode(), urldecode() and urlencode().



rawurldecode
nelson at phprocks dot com
02-Apr-2006 02:18
This function also decodes utf8 strings so it behaves more like the javascript unscape() function.

<?php

function utf8RawUrlDecode ($source) {
  
$decodedStr = "";
  
$pos = 0;
  
$len = strlen ($source);
   while (
$pos < $len) {
      
$charAt = substr ($source, $pos, 1);
       if (
$charAt == '%') {
          
$pos++;
          
$charAt = substr ($source, $pos, 1);
           if (
$charAt == 'u') {
              
// we got a unicode character
              
$pos++;
              
$unicodeHexVal = substr ($source, $pos, 4);
              
$unicode = hexdec ($unicodeHexVal);
              
$entity = "&#". $unicode . ';';
              
$decodedStr .= utf8_encode ($entity);
              
$pos += 4;
           }
           else {
              
// we have an escaped ascii character
              
$hexVal = substr ($source, $pos, 2);
              
$decodedStr .= chr (hexdec ($hexVal));
              
$pos += 2;
           }
       } else {
          
$decodedStr .= $charAt;
          
$pos++;
       }
   }
   return
$decodedStr;
}

?>
php dot net at hiddemann dot org
23-May-2005 02:08
To sum it up: the only difference of this function to the urldecode function is that the "+" character won't get translated.

<parse_urlrawurlencode>
 Last updated: Tue, 15 Nov 2005