note 19687 added to function.rawurldecode
| From: | ronen at greyzone dot com | Date: | Thu, 07 Mar 2002 17:08:03 +0000 |
| Subject: | note 19687 added to function.rawurldecode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27483@lists.php.net to get a copy of this message | ||
This is a unicode safe version of rawurldecode. encoded entities %unnnn n={0..F} get decoded to
matching mutlibyte utf-8 entities.
Note: this function uses utf8Encode() which I posted in the comments section for PHP function
utf8_encode ( http://www.php.net/manual/function.utf8-encode.php
).
/**
* RFC1738 compliant replacement to PHP's rawurldecode - which actually works with unicode
(using utf-8 encoding)
* @param $source [STRING]
* @return unicode safe rawurldecoded string [STRING]
* @access public
*/
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 .= utf8Encode ($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;
}
--
http://www.php.net/manual/en/function.rawurldecode.php
http://master.php.net/manage/user-notes.php?action=edit+19687
http://master.php.net/manage/user-notes.php?action=delete+19687
http://master.php.net/manage/user-notes.php?action=reject+19687