public static function convertCharset($input, $from, $to, $force = false)
    {
        /* Don't bother converting numbers. */
        if (is_numeric($input)) {
            return $input;
        }

        /* If the from and to character sets are identical, return now. */
        if (!$force && $from == $to) {
            return $input;
        }
        $from = self::lower($from);
        $to = self::lower($to);
        if (!$force && $from == $to) {
            return $input;
        }

        if (is_array($input)) {
            $tmp = array();
            foreach ($input as $key => $val) {
                $tmp[self::_convertCharset($key, $from, $to)] = self::convertCharset($val, $from, $to, $force);
            }
            return $tmp;
        }

        if (is_object($input)) {
            // PEAR_Error/Exception objects are almost guaranteed to contain
            // recursion, which will cause a segfault in PHP. We should never
            // reach this line, but add a check.
            if (($input instanceof Exception) ||
                ($input instanceof PEAR_Error)) {
                return '';
            }

            $input = clone $input;
            $vars = get_object_vars($input);
            foreach ($vars as $key => $val) {
                $input->$key = self::convertCharset($val, $from, $to, $force);
            }
            return $input;
        }

        if (!is_string($input)) {
            return $input;
        }

        return self::_convertCharset($input, $from, $to);
    }
public static function convertCharset($input, $from, $to, $force = false)
    {
        /* Don't bother converting numbers. */
        if (is_numeric($input)) {
            return $input;
        }

        /* If the from and to character sets are identical, return now. */
        if (!$force && $from == $to) {
            return $input;
        }
        $from = self::lower($from);
        $to = self::lower($to);
        if (!$force && $from == $to) {
            return $input;
        }

        if (is_array($input)) {
            $tmp = array();
            foreach ($input as $key => $val) {
                $tmp[self::_convertCharset($key, $from, $to)] = self::convertCharset($val, $from, $to, $force);
            }
            return $tmp;
        }

        if (is_object($input)) {
            // PEAR_Error/Exception objects are almost guaranteed to contain
            // recursion, which will cause a segfault in PHP. We should never
            // reach this line, but add a check.
            if (($input instanceof Exception) ||
                ($input instanceof PEAR_Error)) {
                return '';
            }

            $input = clone $input;
            $vars = get_object_vars($input);
            foreach ($vars as $key => $val) {
                $input->$key = self::convertCharset($val, $from, $to, $force);
            }
            return $input;
        }

        if (!is_string($input)) {
            return $input;
        }

        return self::_convertCharset($input, $from, $to);
    }
public static function convertCharset ( $ input , $ from , $ to , $ force = false ) { /* Don't bother converting numbers. */ if ( is_numeric ( $ input ) ) { return $ input ; } /* If the from and to character sets are identical, return now. */ if ( ! $ force && $ from == $ to ) { return $ input ; } $ from = self :: lower ( $ from ) ; $ to = self :: lower ( $ to ) ; if ( ! $ force && $ from == $ to ) { return $ input ; } if ( is_array ( $ input ) ) { $ tmp = array ( ) ; foreach ( $ input as $ key => $ val ) { $ tmp [ self :: _convertCharset ( $ key , $ from , $ to ) ] = self :: convertCharset ( $ val , $ from , $ to , $ force ) ; } return $ tmp ; } if ( is_object ( $ input ) ) { // PEAR_Error/Exception objects are almost guaranteed to contain // recursion, which will cause a segfault in PHP. We should never // reach this line, but add a check. if ( ( $ input instanceof Exception ) || ( $ input instanceof PEAR_Error ) ) { return '' ; } $ input = clone $ input ; $ vars = get_object_vars ( $ input ) ; foreach ( $ vars as $ key => $ val ) { $ input -> $ key = self :: convertCharset ( $ val , $ from , $ to , $ force ) ; } return $ input ; } if ( ! is_string ( $ input ) ) { return $ input ; } return self :: _convertCharset ( $ input , $ from , $ to ) ; }
Converts a string from one charset to another.

Uses the iconv or the mbstring extensions.
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.
@param boolean $force  Force conversion?

@return mixed  The converted input data.
Converts a string from one charset to another .