
iconv_mime_encode 함수의 첫 번째 인자는 헤더 이름을 지정하는 문자열입니다. 예를 들어, Content-Type 헤더를 생성하려면 "Content-Type"을 전달하면 됩니다.
Content-Type 헤더를 생성할 때, charset 인자는 인코딩 방식을 지정하는 문자열입니다. 예를 들어, UTF-8 인코딩을 사용하려면 "UTF-8"을 전달하면 됩니다.
iconv_mime_encode 함수를 사용하는 것이 문자열 인코딩을 위해 가장 적절한 방법은 아닙니다. PHP의 built-in 함수인 mb_convert_encoding()을 사용하는 것이 더 적합합니다.
다음은 iconv_mime_encode 함수를 사용하여 생성한 헤더의 예시입니다.
#hostingforum.kr
php
$headers = iconv_mime_encode("Content-Type", "text/html; charset=UTF-8");
$headers = explode("n", $headers);
$headers = array_map(function($header) {
return trim($header);
}, $headers);
$headers = implode("n", $headers);
print($headers);
이 코드는 Content-Type 헤더를 생성하여 출력합니다. 헤더의 형식은 다음과 같습니다.
#hostingforum.kr
Content-Type: text/html; charset=UTF-8
2025-04-21 20:45