Created
October 2, 2012 11:07
-
-
Save borisguery/3818217 to your computer and use it in GitHub Desktop.
utf8 url decode/encode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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