"함수 encodeURIComponent()"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(다른 사용자 한 명의 중간 판 6개는 보이지 않습니다)
1번째 줄: 1번째 줄:
[[category: String]]
[[category: String]]
;rawurlencode
==개요==
;EncodeURIComponent
;EncodeURIComponent() - JavaScript
;rawurlencode() - PHP
 
{| class='wikitable'
! 입력값 !! 출력값
|-
| <code> </code>(space) || <code>%20</code>
|-
| <code>%</code> || <code>%25</code>
|-
| <code>/</code> || <code>%2F</code>
|}


==Bash==
==Bash==
[[category:Bash]]
[[category:Bash]]
;with Python
{{소스헤더|Python 활용}}
<source lang='Python'>
<syntaxhighlight lang='Python'>
input='hello 123 http://zetawiki.com 한글'
input='hello 123 http://zetawiki.com 한글'
output=`python -c "import urllib; print urllib.quote('''$input''', '')"`
output=`python -c "import urllib; print urllib.quote('''$input''', '')"`
echo $output
echo $output
# hello%20123%20http%3A%2F%2Fzetawiki.com%20%ED%95%9C%EA%B8%80
# hello%20123%20http%3A%2F%2Fzetawiki.com%20%ED%95%9C%EA%B8%80
</source>
</syntaxhighlight>
;with PHP
{{소스헤더|PHP 활용}}
<source lang='Bash'>
<syntaxhighlight lang='Bash'>
input='hello 123 http://zetawiki.com 한글'
input='hello 123 http://zetawiki.com 한글'
output=`php -r "echo rawurlencode('$input');"`
output=`php -r "echo rawurlencode('$input');"`
echo $output
echo $output
# hello%20123%20http%3A%2F%2Fzetawiki.com%20%ED%95%9C%EA%B8%80
# hello%20123%20http%3A%2F%2Fzetawiki.com%20%ED%95%9C%EA%B8%80
</source>
</syntaxhighlight>


==Java==
==Java==
{{참고|자바 rawurlencode()}}
{{참고|자바 rawurlencode()}}
[[분류: Java]]
[[분류: Java]]
<source lang='java'>
<syntaxhighlight lang='java'>
String input = "hello 123 http://zetawiki.com 한글";
String input = "hello 123 http://zetawiki.com 한글";
System.out.println(URLEncoder.encode(input, "UTF-8").replace("*", "%2A").replace("+", "%20").replace("%7E", "~"));
System.out.println(URLEncoder.encode(input, "UTF-8").replace("*", "%2A").replace("+", "%20").replace("%7E", "~"));
// hello%20123%20http%3A%2F%2Fzetawiki.com%20%ED%95%9C%EA%B8%80
// hello%20123%20http%3A%2F%2Fzetawiki.com%20%ED%95%9C%EA%B8%80
</source>
</syntaxhighlight>


==JavaScript==
==JavaScript==
{{참고|자바스크립트 encodeURIComponent()}}
{{참고|자바스크립트 encodeURIComponent()}}
[[category: JavaScript]]
[[category: JavaScript]]
<source lang='JavaScript'>
<syntaxhighlight lang='JavaScript'>
console.log( encodeURIComponent("hello 123 http://zetawiki.com 한글") );
console.log( encodeURIComponent("hello 123 http://zetawiki.com 한글") );
// hello%20123%20http%3A%2F%2Fzetawiki.com%20%ED%95%9C%EA%B8%80
// hello%20123%20http%3A%2F%2Fzetawiki.com%20%ED%95%9C%EA%B8%80
</source>
</syntaxhighlight>
<source lang='JavaScript'>
<syntaxhighlight lang='JavaScript'>
console.log( encodeURIComponent("개요") );
console.log( encodeURIComponent("개요") );
// %EA%B0%9C%EC%9A%94
// %EA%B0%9C%EC%9A%94
</source>
</syntaxhighlight>
<source lang='JavaScript'>
<syntaxhighlight lang='JavaScript'>
console.log( encodeURIComponent("hello") );
console.log( encodeURIComponent("hello") );
// hello
// hello
</source>
</syntaxhighlight>
<source lang='JavaScript'>
<syntaxhighlight lang='JavaScript'>
console.log( encodeURIComponent("%UserProfile%") );
console.log( encodeURIComponent("%UserProfile%") );
// %25UserProfile%25
// %25UserProfile%25
</source>
</syntaxhighlight>


==PHP==
==PHP==
[[category: PHP]]
[[category: PHP]]
<source lang='PHP'>
{{참고|PHP rawurlencode()}}
<syntaxhighlight lang='PHP'>
$input='hello 123 http://zetawiki.com 한글';
$input='hello 123 http://zetawiki.com 한글';
echo rawurlencode($input);
echo rawurlencode($input);
// hello%20123%20http%3A%2F%2Fzetawiki.com%20%ED%95%9C%EA%B8%80
// hello%20123%20http%3A%2F%2Fzetawiki.com%20%ED%95%9C%EA%B8%80
</source>
</syntaxhighlight>


==Python==
==Python==
[[category: Python]]
[[category: Python]]
<source lang='Python'>
<syntaxhighlight lang='Python'>
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import urllib
import urllib
65번째 줄: 77번째 줄:
print urllib.quote(input, '')
print urllib.quote(input, '')
# hello%20123%20http%3A%2F%2Fzetawiki.com%20%ED%95%9C%EA%B8%80
# hello%20123%20http%3A%2F%2Fzetawiki.com%20%ED%95%9C%EA%B8%80
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==
*[[함수 urlencode()]]
*[[함수 urlencode()]]
*[[함수 rawurldecode()]]
*[[함수 rawurldecode()]]

2020년 11월 2일 (월) 02:32 기준 최신판

1 개요[ | ]

EncodeURIComponent() - JavaScript
rawurlencode() - PHP
입력값 출력값
(space) %20
% %25
/ %2F

2 Bash[ | ]

Python 활용
input='hello 123 http://zetawiki.com 한글'
output=`python -c "import urllib; print urllib.quote('''$input''', '')"`
echo $output
# hello%20123%20http%3A%2F%2Fzetawiki.com%20%ED%95%9C%EA%B8%80
PHP 활용
input='hello 123 http://zetawiki.com 한글'
output=`php -r "echo rawurlencode('$input');"`
echo $output
# hello%20123%20http%3A%2F%2Fzetawiki.com%20%ED%95%9C%EA%B8%80

3 Java[ | ]

String input = "hello 123 http://zetawiki.com 한글";
System.out.println(URLEncoder.encode(input, "UTF-8").replace("*", "%2A").replace("+", "%20").replace("%7E", "~"));
// hello%20123%20http%3A%2F%2Fzetawiki.com%20%ED%95%9C%EA%B8%80

4 JavaScript[ | ]

console.log( encodeURIComponent("hello 123 http://zetawiki.com 한글") );
// hello%20123%20http%3A%2F%2Fzetawiki.com%20%ED%95%9C%EA%B8%80
console.log( encodeURIComponent("개요") );
// %EA%B0%9C%EC%9A%94
console.log( encodeURIComponent("hello") );
// hello
console.log( encodeURIComponent("%UserProfile%") );
// %25UserProfile%25

5 PHP[ | ]

$input='hello 123 http://zetawiki.com 한글';
echo rawurlencode($input);
// hello%20123%20http%3A%2F%2Fzetawiki.com%20%ED%95%9C%EA%B8%80

6 Python[ | ]

# -*- coding: utf-8 -*-
import urllib
input = 'hello 123 http://zetawiki.com 한글'
print urllib.quote(input, '')
# hello%20123%20http%3A%2F%2Fzetawiki.com%20%ED%95%9C%EA%B8%80

7 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}