Created
December 15, 2010 02:45
-
-
Save kosh04/741550 to your computer and use it in GitHub Desktop.
いろいろな言語でURLエンコード
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
#!/bin/bash | |
# 標準入力を URL エンコードする | |
# NOTE: urldecode は urlencode のシンボリックリンクとする | |
urlencode() { | |
# echo -n ${1-`cat`} | od -t x1 -A n | tr " " % | tr -d "\n" | |
# perl -pe 's/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg' | |
python -c 'import sys, urllib; print urllib.quote(sys.stdin.read()),' | |
# php -r 'echo urlencode(file_get_contents("php://stdin"))."\n";' | |
} | |
urldecode() { | |
# echo -e "$(sed -e 'y/+/ /; s/%\([[:xdigit:]]\{2\}\)/\\x\1/g')" | |
# perl -pe 's/%([0-9a-f]{2})/sprintf("%s", pack("H2", $1))/eig' | |
python -c 'import sys, urllib; print urllib.unquote_plus(sys.stdin.read()),' | |
# php -r 'echo urldecode(file_get_contents("php://stdin"));' | |
} | |
if [ `basename $0` = "urldecode" ] | |
then | |
urldecode ${@+"$@"} | |
else | |
urlencode ${@+"$@"} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment