本文整理匯總了PHP中MailSo\Base\Utils::normalizeCharset方法的典型用法代碼示例。如果您正苦於以下問題:PHP Utils::normalizeCharset方法的具體用法?PHP Utils::normalizeCharset怎麽用?PHP Utils::normalizeCharset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MailSo\Base\Utils
的用法示例。
在下文中一共展示了Utils::normalizeCharset方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: ConvertEncoding
/**
* @param string $sInputString
* @param string $sInputFromEncoding
* @param string $sInputToEncoding
*
* @return string
*/
public static function ConvertEncoding($sInputString, $sInputFromEncoding, $sInputToEncoding)
{
$sResult = $sInputString;
$sFromEncoding = \MailSo\Base\Utils::normalizeCharset($sInputFromEncoding);
$sToEncoding = \MailSo\Base\Utils::normalizeCharset($sInputToEncoding);
if ('' === \trim($sResult) || $sFromEncoding === $sToEncoding && \MailSo\Base\Enumerations\Charset::UTF_8 !== $sFromEncoding) {
return $sResult;
}
$bUnknown = false;
switch (true) {
default:
$bUnknown = true;
break;
case $sFromEncoding === \MailSo\Base\Enumerations\Charset::ISO_8859_1 && $sToEncoding === \MailSo\Base\Enumerations\Charset::UTF_8 && \function_exists('utf8_encode'):
$sResult = \utf8_encode($sResult);
break;
case $sFromEncoding === \MailSo\Base\Enumerations\Charset::UTF_8 && $sToEncoding === \MailSo\Base\Enumerations\Charset::ISO_8859_1 && \function_exists('utf8_decode'):
$sResult = \utf8_decode($sResult);
break;
case $sFromEncoding === \MailSo\Base\Enumerations\Charset::UTF_7_IMAP && $sToEncoding === \MailSo\Base\Enumerations\Charset::UTF_8:
$sResult = \MailSo\Base\Utils::Utf7ModifiedToUtf8($sResult);
if (false === $sResult) {
$sResult = $sInputString;
}
break;
case $sFromEncoding === \MailSo\Base\Enumerations\Charset::UTF_8 && $sToEncoding === \MailSo\Base\Enumerations\Charset::UTF_7_IMAP:
$sResult = \MailSo\Base\Utils::Utf8ToUtf7Modified($sResult);
if (false === $sResult) {
$sResult = $sInputString;
}
break;
case $sFromEncoding === \MailSo\Base\Enumerations\Charset::UTF_7_IMAP:
$sResult = \MailSo\Base\Utils::ConvertEncoding(\MailSo\Base\Utils::ModifiedToPlainUtf7($sResult), \MailSo\Base\Enumerations\Charset::UTF_7, $sToEncoding);
break;
case \in_array(\strtolower($sFromEncoding), \MailSo\Base\Utils::$SuppostedCharsets):
if (\MailSo\Base\Utils::IsIconvSupported()) {
$sResult = @\iconv(\strtoupper($sFromEncoding), \strtoupper($sToEncoding) . '//IGNORE', $sResult);
} else {
if (\MailSo\Base\Utils::IsMbStringSupported()) {
$sResult = @\mb_convert_encoding($sResult, \strtoupper($sToEncoding), \strtoupper($sFromEncoding));
} else {
if (\MailSo\Base\Utils::IsLibIconvSupported()) {
$sResult = @\libiconv(\strtoupper($sFromEncoding), \strtoupper($sToEncoding), $sResult);
}
}
}
$sResult = false !== $sResult ? $sResult : $sInputString;
break;
}
if ($bUnknown && \MailSo\Base\Utils::IsMbStringSupported()) {
$sResult = @\mb_convert_encoding($sResult, $sToEncoding);
}
return $sResult;
}