note 21547 added to function.urldecode
| From: | igjav at cesga dot es | Date: | Thu, 16 May 2002 15:48:58 +0000 |
| Subject: | note 21547 added to function.urldecode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-30722@lists.php.net to get a copy of this message | ||
This seems to decode correctly between most browsers and charater coding configurations. Specially
indicated for direct parsing of URL as it comes on environment variables:
function crossUrlDecode($source) {
$decodedStr = '';
$pos = 0;
$len = strlen($source);
while ($pos < $len) {
$charAt = substr ($source, $pos, 1);
if ($charAt == 'Ã') {
$char2 = substr($source, $pos, 2);
$decodedStr .= htmlentities(utf8_decode($char2),ENT_QUOTES,'ISO-8859-1');
$pos += 2;
}
elseif(ord($charAt) > 127) {
$decodedStr .= "&#".ord($charAt).";";
$pos++;
}
elseif($charAt == '%') {
$pos++;
$hex2 = substr($source, $pos, 2);
$dechex = chr(hexdec($hex2));
if($dechex == 'Ã') {
$pos += 2;
if(substr($source, $pos, 1) == '%') {
$pos++;
$char2a = chr(hexdec(substr($source, $pos, 2)));
$decodedStr .= htmlentities(utf8_decode($dechex . $char2a),ENT_QUOTES,'ISO-8859-1');
}
else {
$decodedStr .= htmlentities(utf8_decode($dechex));
}
}
else {
$decodedStr .= $dechex;
}
$pos += 2;
}
else {
$decodedStr .= $charAt;
$pos++;
}
}
return $decodedStr;
}
--
http://www.php.net/manual/en/function.urldecode.php
http://master.php.net/manage/user-notes.php?action=edit+21547
http://master.php.net/manage/user-notes.php?action=delete+21547
http://master.php.net/manage/user-notes.php?action=reject+21547