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

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
2번째 줄: 2번째 줄:
[[분류:JavaScript]]
[[분류:JavaScript]]
{{참고|JavaScript encodeURI()}}
{{참고|JavaScript encodeURI()}}
<source lang='javascript'>
<syntaxhighlight lang='javascript'>
console.log( encodeURI("?") );
console.log( encodeURI("?") );
// ?
// ?
</source>
</syntaxhighlight>
<source lang='javascript'>
<syntaxhighlight lang='javascript'>
console.log( encodeURI("http://www.Not a URL.com") );
console.log( encodeURI("http://www.Not a URL.com") );
// http://www.Not%20a%20URL.com
// http://www.Not%20a%20URL.com
</source>
</syntaxhighlight>
<source lang='javascript'>
<syntaxhighlight lang='javascript'>
console.log( encodeURI('https://example.com/?x=안녕') );
console.log( encodeURI('https://example.com/?x=안녕') );
// https://example.com/?x=%EC%95%88%EB%85%95
// https://example.com/?x=%EC%95%88%EB%85%95
</source>
</syntaxhighlight>


==PHP==
==PHP==
[[분류: PHP]]
[[분류: PHP]]
{{참고|PHP encodeURI()}}
{{참고|PHP encodeURI()}}
<source lang='php'>
<syntaxhighlight lang='php'>
function encodeURI($url) {
function encodeURI($url) {
return strtr(rawurlencode($url),[
return strtr(rawurlencode($url),[
32번째 줄: 32번째 줄:
# string(28) "http://www.Not%20a%20URL.com"
# string(28) "http://www.Not%20a%20URL.com"
# string(41) "https://example.com/?x=%EC%95%88%EB%85%95"
# string(41) "https://example.com/?x=%EC%95%88%EB%85%95"
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

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

1 JavaScript[ | ]

console.log( encodeURI("?") );
// ?
console.log( encodeURI("http://www.Not a URL.com") );
// http://www.Not%20a%20URL.com
console.log( encodeURI('https://example.com/?x=안녕') );
// https://example.com/?x=%EC%95%88%EB%85%95

2 PHP[ | ]

function encodeURI($url) {
	return strtr(rawurlencode($url),[
		'%2D'=>'-','%5F'=>'_','%2E'=>'.','%21'=>'!','%7E'=>'~',
		'%2A'=>'*','%27'=>"'",'%28'=>'(','%29'=>')','%3B'=>';',
		'%2C'=>',','%2F'=>'/','%3F'=>'?','%3A'=>':','%40'=>'@',
		'%26'=>'&','%3D'=>'=','%2B'=>'+','%24'=>'$','%23'=>'#']);
}
var_dump( encodeURI("?") );
var_dump( encodeURI("http://www.Not a URL.com") );
var_dump( encodeURI('https://example.com/?x=안녕') );
# string(1) "?"
# string(28) "http://www.Not%20a%20URL.com"
# string(41) "https://example.com/?x=%EC%95%88%EB%85%95"

3 같이 보기[ | ]

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