本文整理汇总了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);
}