라이브러리

[PHP] mb_convert_encoding - 문자열을 한 문자 인코딩에서 다른 문자 인코딩으로 변환


PHP에서 `mb_convert_encoding` 함수는 문자열을 다른 인코딩 형식으로 변환하는 데 사용됩니다. 이 함수는 멀티바이트 문자열을 처리할 수 있으므로, PHP에서 멀티바이트 문자열을 다룰 때 유용합니다.

mb_convert_encoding 함수의 사용법


`mb_convert_encoding` 함수의 사용법은 다음과 같습니다.

#hostingforum.kr
php

string mb_convert_encoding ( string $str , string $to_encoding , string $from_encoding )



- `$str`: 변환할 문자열
- `$to_encoding`: 변환할 인코딩 형식
- `$from_encoding`: 현재 인코딩 형식

예제


다음 예제에서는 `mb_convert_encoding` 함수를 사용하여 문자열을 UTF-8 인코딩 형식으로 변환하는 방법을 보여줍니다.

#hostingforum.kr
php

// 원본 문자열

$str = "Hello, World!";



// 원본 인코딩 형식

$from_encoding = "ISO-8859-1";



// 변환할 인코딩 형식

$to_encoding = "UTF-8";



// 변환

$converted_str = mb_convert_encoding($str, $to_encoding, $from_encoding);



// 결과

echo "원본 문자열: $str
";

echo "원본 인코딩 형식: $from_encoding
";

echo "변환할 인코딩 형식: $to_encoding
";

echo "변환된 문자열: $converted_str
";



이 예제에서는 원본 문자열 `"Hello, World!"`을 `ISO-8859-1` 인코딩 형식에서 `UTF-8` 인코딩 형식으로 변환합니다.

결과


#hostingforum.kr


원본 문자열: Hello, World!

원본 인코딩 형식: ISO-8859-1

변환할 인코딩 형식: UTF-8

변환된 문자열: Hello, World!



참고


- `mb_convert_encoding` 함수는 멀티바이트 문자열을 처리할 수 있으므로, PHP에서 멀티바이트 문자열을 다룰 때 유용합니다.
- 이 함수는 문자열을 다른 인코딩 형식으로 변환할 수 있으므로, 데이터를 전송하거나 저장할 때 인코딩 형식이 다를 경우 사용할 수 있습니다.
- 이 함수는 PHP 4.0.6 이상에서 사용할 수 있습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

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

검색

게시물 검색