
rawurlencode 함수는 URL을 인코딩하는 데 사용되는 PHP 함수입니다. 이 함수는 URL에서 사용할 수 없는 특수문자, 공백, 기호를 %로 인코딩하여 URL을 안전하게 만듭니다.
URL 인코딩 규칙은 다음과 같습니다.
- 공백은 %20으로 인코딩됩니다.
- 특수문자는 %로 인코딩됩니다. 예를 들어, !은 %21로 인코딩됩니다.
- 기호는 %로 인코딩됩니다. 예를 들어, /은 %2F로 인코딩됩니다.
예를 들어, "http://example.com/test?param=hello world" URL을 인코딩하면 "http://example.com/test?param=hello%20world"이 됩니다.
특수문자, 공백, 기호를 처리하는 방법은 다음과 같습니다.
- 공백: %20으로 인코딩
- 특수문자: %로 인코딩 (예: ! -> %21, @ -> %40)
- 기호: %로 인코딩 (예: / -> %2F, : -> %3A)
예를 들어, "http://example.com/test?param=hello!world" URL을 인코딩하면 "http://example.com/test?param=hello%21world"이 됩니다.
rawurlencode 함수를 사용하는 예제는 다음과 같습니다.
#hostingforum.kr
php
$url = "http://example.com/test?param=hello world";
$encodedUrl = rawurlencode($url);
echo $encodedUrl; // http://example.com/test?param=hello%20world
이 예제에서는 "hello world" 문자열을 URL 인코딩하여 "%20"로 인코딩된 문자열을 생성합니다.
2025-06-02 08:15