note 79595 added to function.urldecode
| From: | mkaganer at gmail dot com | Date: | Tue, 04 Dec 2007 22:58:12 +0000 |
| Subject: | note 79595 added to function.urldecode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132821@lists.php.net to get a copy of this message | ||
B.H.
I had troubles converting Unicode-encoded data in $_GET (like this: %u05D8%u05D1%u05E2) which is
generated by JavaScript's escape() function to UTF8 for server-side processing.
Finally, i've found a simple solution (only 3 lines of code) that does it (at least in my
configuration):
<?php
function utf8_urldecode($str) {
$str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str));
return html_entity_decode($str,null,'UTF-8');;
}
?>
note that documentation for html_entity_decode() states that "Support for multi-byte character
sets was added at PHP 5.0.0" so this might not work for PHP 4
----
Server IP: 212.199.163.191
Probable Submitter: 84.94.85.201 (proxied: 84.94.85.201)
----
Manual Page -- http://www.php.net/manual/en/function.urldecode.php
Edit -- https://master.php.net/note/edit/79595
Del: integrated -- https://master.php.net/note/delete/79595/integrated
Del: useless -- https://master.php.net/note/delete/79595/useless
Del: bad code -- https://master.php.net/note/delete/79595/bad+code
Del: spam -- https://master.php.net/note/delete/79595/spam
Del: non-english -- https://master.php.net/note/delete/79595/non-english
Del: in docs -- https://master.php.net/note/delete/79595/in+docs
Del: other reasons-- https://master.php.net/note/delete/79595
Reject -- https://master.php.net/note/reject/79595
Search -- https://master.php.net/manage/user-notes.php