라이브러리

[JAVASCRIPT] encodeURI(uri) - URI를 인코딩하여 특수 문자를 이스케이프




encodeURI(uri) 함수


JavaScript의 `encodeURI(uri)` 함수는 URI(Uniform Resource Identifier) 또는 URL(Uniform Resource Locator)을 인코딩하는 데 사용됩니다. 이 함수는 URI의 일부를 인코딩하지 않습니다. 대신, URI의 모든 특수 문자를 인코딩하여 URL-safe한 문자열로 변환합니다.

인코딩 규칙


`encodeURI(uri)` 함수는 다음 규칙을 따릅니다.

* `%` 문자는 `%25`로 인코딩됩니다.
* `$` 문자는 `%24`로 인코딩됩니다.
* `&` 문자는 `%26`로 인코딩됩니다.
* `+` 문자는 `%2B`로 인코딩됩니다.
* `,` 문자는 `%2C`로 인코딩됩니다.
* `/` 문자는 `%2F`로 인코딩됩니다.
* `:` 문자는 `%3A`로 인코딩됩니다.
* `;` 문자는 `%3B`로 인코딩됩니다.
* `<` 문자는 `%3C`로 인코딩됩니다.
* `=` 문자는 `%3D`로 인코딩됩니다.
* `>` 문자는 `%3E`로 인코딩됩니다.
* `?` 문자는 `%3F`로 인코딩됩니다.
* `@` 문자는 `%40`로 인코딩됩니다.
* `[` 문자는 `%5B`로 인코딩됩니다.
* `` 문자는 `%5C`로 인코딩됩니다.
* `]` 문자는 `%5D`로 인코딩됩니다.
* `^` 문자는 `%5E`로 인코딩됩니다.
* `_` 문자는 `%5F`로 인코딩됩니다.
* `~` 문자는 `%7E`로 인코딩됩니다.

예제


#hostingforum.kr
javascript

const uri = "https://example.com/path?query=param#fragment";

const encodedUri = encodeURI(uri);



console.log(encodedUri);

// Output: https://example.com/path?query=param#fragment



위 예제에서는 `encodeURI(uri)` 함수를 사용하여 URI를 인코딩합니다. 결과는 원래 URI와 동일합니다.

다른 예제


#hostingforum.kr
javascript

const uri = "https://example.com/path?query=param&param2=value";

const encodedUri = encodeURI(uri);



console.log(encodedUri);

// Output: https://example.com/path?query=param&param2=value



위 예제에서는 `encodeURI(uri)` 함수를 사용하여 URI를 인코딩합니다. 결과는 원래 URI와 동일합니다.

참고


* `encodeURI(uri)` 함수는 URI의 일부를 인코딩하지 않습니다. 대신, URI의 모든 특수 문자를 인코딩하여 URL-safe한 문자열로 변환합니다.
* `encodeURI(uri)` 함수는 `encodeURIComponent(uri)` 함수와 다릅니다. `encodeURIComponent(uri)` 함수는 URI의 일부를 인코딩합니다.
* `encodeURI(uri)` 함수는 URL-safe한 문자열로 변환합니다. 하지만, 이 함수는 URI의 일부를 인코딩하지 않습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 1 페이지

검색

게시물 검색