PHP函式:UConverter::getDestinationEncoding()
適用版本:PHP 7.4.0 以上
用法:UConverter::getDestinationEncoding() 函式用於獲取當前 UConverter 物件的目標編碼。
示例:
// 建立 UConverter 物件
$converter = UConverter::open('UTF-8', 'ISO-8859-1');
// 獲取目標編碼
$destinationEncoding = $converter->getDestinationEncoding();
echo "目標編碼: " . $destinationEncoding;
// 關閉 UConverter 物件
$converter->close();
在上面的示例中,我們首先建立了一個 UConverter 物件,使用 UTF-8 編碼轉換為 ISO-8859-1 編碼。然後,透過呼叫 getDestinationEncoding()
方法,我們獲取了當前 UConverter 物件的目標編碼,並將其列印出來。
請注意,使用此函式之前,需要安裝 intl
擴充套件,並啟用 intl.use_exceptions
配置項,以便在出現錯誤時丟擲異常。
輸出結果類似於:
目標編碼: ISO-8859-1