Skip to content

Instantly share code, notes, and snippets.

@borisguery
Created October 2, 2012 11:07
Show Gist options
  • Save borisguery/3818217 to your computer and use it in GitHub Desktop.
Save borisguery/3818217 to your computer and use it in GitHub Desktop.
utf8 url decode/encode
<?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');;
}
// Main
$options = getopt('de');
if ($argc == 3) {
if (isset($options['d'])) {
printf("Decoded: %s => %s\n", $argv[2], utf8_urldecode($argv[2]));
exit(0);
} elseif (isset($options['e'])) {
printf("Encoded: %s => %s\n", $argv[2], urlencode($argv[2]));
exit(0);
}
} else {
printf("Usage: %s -d|-e string\n", $argv[0]);
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment