本文整理匯總了PHP中IPSText::classConvertCharset方法的典型用法代碼示例。如果您正苦於以下問題:PHP IPSText::classConvertCharset方法的具體用法?PHP IPSText::classConvertCharset怎麽用?PHP IPSText::classConvertCharset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類IPSText
的用法示例。
在下文中一共展示了IPSText::classConvertCharset方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: convertCharsets
/**
* Convert a string between charsets
*
* @access public
* @param string Input String
* @param string Current char set
* @param string Destination char set
* @return string Parsed string
* @since 2.1.0
* @todo [Future] If an error is set in classConvertCharset, show it or log it somehow
*/
public static function convertCharsets($text, $original_cset, $destination_cset = "UTF-8")
{
$original_cset = strtolower($original_cset);
$t = $text;
//-----------------------------------------
// Not the same?
//-----------------------------------------
if ($destination_cset == $original_cset) {
return $t;
}
if (!is_object(self::$classConvertCharset)) {
require_once IPS_KERNEL_PATH . '/classConvertCharset.php';
self::$classConvertCharset = new classConvertCharset();
//if ( function_exists( 'mb_convert_encoding' ) )
//{
// self::$classConvertCharset->method = 'mb';
//}
//else if ( function_exists( 'iconv' ) )
//{
// self::$classConvertCharset->method = 'iconv';
//}
//else if ( function_exists( 'recode_string' ) )
//{
// self::$classConvertCharset->method = 'recode';
//}
//else
//{
self::$classConvertCharset->method = 'internal';
//}
}
$text = self::$classConvertCharset->convertEncoding($text, $original_cset, $destination_cset);
return $text ? $text : $t;
}
示例2: convertCharsets
/**
* Convert a string between charsets
*
* @param string Input String
* @param string Current char set
* @param string Destination char set
* @return string Parsed string
* @since 2.1.0
* @todo [Future] If an error is set in classConvertCharset, show it or log it somehow
*/
public static function convertCharsets($text, $original_cset, $destination_cset = "UTF-8")
{
define('CONVERT_JSU_TO_ENTITY', true);
$original_cset = strtolower($original_cset);
$destination_cset = strtolower($destination_cset);
$t = $text;
//-----------------------------------------
// Not the same?
//-----------------------------------------
if ($destination_cset == $original_cset) {
return $t;
}
//-----------------------------------------
// Are these only latin chars? If so, no conversion should be needed.
//-----------------------------------------
if (preg_match('/^([a-zA-Z0-9_\\-\\.:;\\[\\]]+?)$/', $t)) {
return $text;
}
if (!is_object(self::$classConvertCharset)) {
require_once IPS_KERNEL_PATH . '/classConvertCharset.php';
/*noLibHook*/
self::$classConvertCharset = new classConvertCharset();
if (ipsRegistry::$settings['charset_conv_method'] == 'mb' and function_exists('mb_convert_encoding')) {
self::$classConvertCharset->method = 'mb';
} else {
if (ipsRegistry::$settings['charset_conv_method'] == 'iconv' and function_exists('iconv')) {
self::$classConvertCharset->method = 'iconv';
} else {
if (ipsRegistry::$settings['charset_conv_method'] == 'recode' and function_exists('recode_string')) {
self::$classConvertCharset->method = 'recode';
} else {
self::$classConvertCharset->method = 'internal';
}
}
}
}
$text = self::$classConvertCharset->convertEncoding($text, $original_cset, $destination_cset);
/* Experimental - convert \u#### to html entity */
if ($destination_cset != 'utf-8' and $text and CONVERT_JSU_TO_ENTITY) {
preg_match_all('#\\\\u([0-9]{4})#ims', $text, $matches);
if (is_array($matches) and count($matches)) {
foreach ($matches[1] as $k => $v) {
$v = "&#" . hexdec(ltrim($v, '0')) . ";";
$text = str_replace($matches[0][$k], $v, $text);
}
}
}
return $text ? $text : $t;
}