1 개요[ | ]
- urlencode
- urllib.quote_plus
- urldecode()의 역함수
- URL을 쿼리스트링으로 넘길 수 있도록 변환 가능
- 이 목적이라면 함수 rawurlencode()를 사용해도 됨
입력값 | 출력값 |
---|---|
(space) |
+
|
/ |
%2F
|
% |
%25
|
2 Bash[ | ]
- with Python
Bash
Copy
input='hello 123 http://zetawiki.com 한글'
output=`python -c "import urllib; print urllib.quote_plus('''$input''')"`
echo $output
# hello+123+http%3A%2F%2Fzetawiki.com+%ED%95%9C%EA%B8%80
- with PHP
Bash
Copy
input='hello 123 http://zetawiki.com 한글'
output=`php -r "echo urlencode('$input');"`
echo $output
# hello+123+http%3A%2F%2Fzetawiki.com+%ED%95%9C%EA%B8%80
3 Java[ | ]

Java
Copy
String input = "hello 123 http://zetawiki.com 한글";
String encoded = URLEncoder.encode(input, "UTF-8");
System.out.println(encoded);
// hello+123+http%3A%2F%2Fzetawiki.com+%ED%95%9C%EA%B8%80
4 JavaScript[ | ]

JavaScript
Copy
function urlencode(str) {
return encodeURIComponent(str+'').replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}
5 PHP[ | ]

PHP
Copy
echo urlencode('개요');
# %EA%B0%9C%EC%9A%94
echo urlencode('hello 123 http://zetawiki.com 한글');
# hello+123+http%3A%2F%2Fzetawiki.com+%ED%95%9C%EA%B8%80
6 Python[ | ]
Python 2
Python
Copy
# -*- coding: utf-8 -*-
import urllib
print urllib.quote_plus('hello 123 http://zetawiki.com 한글')
# hello+123+http%3A%2F%2Fzetawiki.com+%ED%95%9C%EA%B8%80
7 R[ | ]
R
Copy
# Windows (CP949) 예시
s <- 'hello 123 http://zetawiki.com 한글'
gsub('%20','+',URLencode(iconv(s,'CP949','UTF-8'),reserved=T))
## [1] "hello+123+http%3A%2F%2Fzetawiki.com+%ED%95%9C%EA%B8%80"
8 같이 보기[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.
리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― Jmnote리눅스 Python 2.7 컴파일 설치 ― ㅇㅇㅇ미운코딩새끼 ― 승호 도령미운코딩새끼 ― 불탄고등어미운코딩새끼 ― 김레이미운코딩새끼 ― 호박이미운코딩새끼 ― Junhg0211미운코딩새끼 ― 김왼손미운코딩새끼 ― 용딘이미운코딩새끼 ―Pinkcrimson
유기농냠냠파이썬 ― 호박유기농냠냠파이썬 ― 이에스유기농냠냠파이썬 ― 이승현파이썬 global ― Jmnote파이썬 global ― John Jeong파이썬 global ― Jmnote파이썬 global ― John Jeong파이썬 global ― John Jeong파이썬 global ― John Jeong파이썬 global ― Jmnote파이썬 global ― John Jeong