라이브러리

[PHP] rawurlencode - RFC 3986에 따른 URL 인코딩




PHP에서 rawurlencode() 함수


`rawurlencode()` 함수는 URL에 포함될 문자열을 URL 인코딩하는 데 사용됩니다. 이 함수는 UTF-8 인코딩을 사용하여 문자열을 인코딩합니다.

# 사용법


`rawurlencode()` 함수는 다음과 같이 사용됩니다.

#hostingforum.kr
php

string rawurlencode ( string $str )



* `$str` : 인코딩할 문자열

# 예제


#hostingforum.kr
php

// 예제 1: URL 인코딩

$str = "https://example.com/path?query=Hello, World!";

$encodedStr = rawurlencode($str);

echo $encodedStr; // https%3A%2F%2Fexample.com%2Fpath%3Fquery%3DHello%2C%20World%21



// 예제 2: 특수문자 인코딩

$str = "https://example.com/path?query=Hello, World!#anchor";

$encodedStr = rawurlencode($str);

echo $encodedStr; // https%3A%2F%2Fexample.com%2Fpath%3Fquery%3DHello%2C%20World%21%23anchor



// 예제 3: 한글 인코딩

$str = "https://example.com/path?query=안녕하세요";

$encodedStr = rawurlencode($str);

echo $encodedStr; // https%3A%2F%2Fexample.com%2Fpath%3Fquery%3D%EC%95%88%EB%85%90%ED%95%9C%EC%8B%AC%EB%8A%94



# 주의사항


* `rawurlencode()` 함수는 UTF-8 인코딩을 사용하므로, 한글이나 기타 유니코드 문자를 인코딩할 때 사용해야 합니다.
* 이 함수는 URL 인코딩을 위해 사용되므로, URL의 경로, 쿼리 문자열, 해시 등 모든 부분을 인코딩해야 합니다.
* 이 함수는 문자열을 인코딩할 때, `%` 문자를 `%25`로 인코딩합니다. 따라서, `%` 문자를 인코딩할 때는 `%25`를 사용해야 합니다.

참고자료


* PHP 공식 문서: [rawurlencode()](https://www.php.net/manual/kr/function.rawurlencode.php)
* W3C: [URL Encoding](https://www.w3.org/International/questions/qa-encoding-declarations)
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

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

검색

게시물 검색