rawurldecode

(PHP 3, PHP 4, PHP 5)

rawurldecode -- 对已编码的 URL 字符串进行解码

描述

string rawurldecode ( string str )

返回字符串,此字符串中百分号(%)后跟两位十六进制数的序列都将被替换成原义字符。

例子 1. rawurldecode() 示例

<?php

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

?>

注: rawurldecode() 不会把加号('+')解码为空格,而 urldecode() 可以。

参见 rawurlencode()urldecode()urlencode()


add a note add a note User Contributed Notes
nelson at phprocks dot com
03-Apr-2006 05: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
24-May-2005 05:08
To sum it up: the only difference of this function to the urldecode function is that the "+" character won't get translated.