本文整理匯總了PHP中Horde_String::_convertCharset方法的典型用法代碼示例。如果您正苦於以下問題:PHP Horde_String::_convertCharset方法的具體用法?PHP Horde_String::_convertCharset怎麽用?PHP Horde_String::_convertCharset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Horde_String
的用法示例。
在下文中一共展示了Horde_String::_convertCharset方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: convertCharset
/**
* Converts a string from one charset to another.
*
* Works only if either the iconv or the mbstring extension
* are present and best if both are available.
* The original string is returned if conversion failed or none
* of the extensions were available.
*
* @param mixed $input The data to be converted. If $input is an an array,
* the array's values get converted recursively.
* @param string $from The string's current charset.
* @param string $to The charset to convert the string to. If not
* specified, the global variable
* $_HORDE_STRING_CHARSET will be used.
*
* @return mixed The converted input data.
*/
public function convertCharset($input, $from, $to = null)
{
/* Don't bother converting numbers. */
if (is_numeric($input)) {
return $input;
}
/* Get the user's default character set if none passed in. */
if (is_null($to)) {
$to = self::$charset;
}
/* If the from and to character sets are identical, return now. */
$from = Horde_String::lower($from);
$to = Horde_String::lower($to);
if ($from == $to) {
return $input;
}
if (is_array($input)) {
$tmp = array();
reset($input);
while (list($key, $val) = each($input)) {
$tmp[Horde_String::_convertCharset($key, $from, $to)] = Horde_String::convertCharset($val, $from, $to);
}
return $tmp;
}
if (is_object($input)) {
$vars = get_object_vars($input);
while (list($key, $val) = each($vars)) {
$input->{$key} = Horde_String::convertCharset($val, $from, $to);
}
return $input;
}
if (!is_string($input)) {
return $input;
}
return Horde_String::_convertCharset($input, $from, $to);
}