라이브러리
[PHP] UConverter::getDestinationEncoding - 대상 인코딩 가져오기
UConverter::getDestinationEncoding
UConverter는 PHP 7.4에서 추가된 클래스로, ICU(International Components for Unicode) 라이브러리를 사용하여 문자열을 다른 인코딩으로 변환하는 데 사용됩니다. UConverter::getDestinationEncoding은 UConverter 인스턴스에서 지원하는 목적 인코딩 목록을 반환하는 메서드입니다.
# 사용 예제
#hostingforum.kr
php
// UConverter 인스턴스 생성
$uConverter = new UConverter('UTF-8', 'EUC-KR');
// 목적 인코딩 목록을 가져옵니다.
$destinationEncodings = $uConverter->getDestinationEncodings();
// 목적 인코딩 목록을 출력합니다.
foreach ($destinationEncodings as $encoding) {
echo "$encoding
";
}
# 목적 인코딩 목록
목적 인코딩 목록은 UConverter 인스턴스에서 지원하는 모든 인코딩 목록을 반환합니다. 예를 들어, 위의 예제에서 `UTF-8`에서 `EUC-KR`로 변환할 수 있는 목적 인코딩 목록은 다음과 같습니다.
#hostingforum.kr
EUC-KR
ISO-2022-KR
ISO-2022-JP
ISO-2022-CN
ISO-2022-JP-2
ISO-2022-CN-EXT
ISO-2022-KR-EXT
# 변환 예제
#hostingforum.kr
php
// UConverter 인스턴스 생성
$uConverter = new UConverter('UTF-8', 'EUC-KR');
// 변환할 문자열
$sourceString = 'Hello, World!';
// 목적 인코딩을 지정합니다.
$destinationEncoding = 'EUC-KR';
// 변환합니다.
$convertedString = $uConverter->convert($sourceString, $destinationEncoding);
// 변환된 문자열을 출력합니다.
echo "$convertedString
";
# 변환 결과
변환 결과는 다음과 같습니다.
#hostingforum.kr
?Hello, World!
# 주의사항
UConverter 클래스는 PHP 7.4에서 추가된 클래스로, PHP 7.3 미만 버전에서는 사용할 수 없습니다. 또한, UConverter 인스턴스를 생성할 때 인코딩을 지정해야 하며, 변환할 문자열을 지정해야 합니다. 목적 인코딩을 지정하지 않으면 기본 인코딩으로 변환됩니다.
# 참고자료
* [UConverter 클래스](https://www.php.net/manual/en/class.uconverter.php)
* [UConverter::getDestinationEncoding 메서드](https://www.php.net/manual/en/uconverter.getdestinationencoding.php)
* [UConverter::convert 메서드](https://www.php.net/manual/en/uconverter.convert.php)
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.