함수 encodeURIComponent()

Jmnote (토론 | 기여)님의 2017년 9월 29일 (금) 21:35 판 (→‎JavaScript)
rawurlencode
EncodeURIComponent

1 Bash

with 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
with 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

2 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

3 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

4 PHP

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

5 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

6 같이 보기

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