fromUnicode

@param array $arr

@note  Port of phputf8's utf8_from_unicode()

@return  bool|string
173291
public static function fromUnicode($arr)
    {
        ob_start();

        foreach (array_keys($arr) as $k) {
            # ASCII range (including control chars)
            if (($arr[$k] >= 0) && ($arr[$k] <= 0x007f)) {
                echo chr($arr[$k]);
                # 2 byte sequence
            } else {
                if ($arr[$k] <= 0x07ff) {
                    echo chr(0xc0 | ($arr[$k] >> 6));
                    echo chr(0x80 | ($arr[$k] & 0x003f));
                    # Byte order mark (skip)
                } else {
                    if ($arr[$k] == 0xFEFF) {
                        // nop -- zap the BOM

                        # Test for illegal surrogates
                    } else {
                        if ($arr[$k] >= 0xD800 && $arr[$k] <= 0xDFFF) {
                            // found a surrogate
                            trigger_error(
                                'utf8_from_unicode: Illegal surrogate ' .
                                'at index: ' . $k . ', value: ' . $arr[$k],
                                E_USER_WARNING
                            );

                            return false;
                            # 3 byte sequence
                        } else {
                            if ($arr[$k] <= 0xffff) {
                                echo chr(0xe0 | ($arr[$k] >> 12));
                                echo chr(0x80 | (($arr[$k] >> 6) & 0x003f));
                                echo chr(0x80 | ($arr[$k] & 0x003f));
                                # 4 byte sequence
                            } else {
                                if ($arr[$k] <= 0x10ffff) {
                                    echo chr(0xf0 | ($arr[$k] >> 18));
                                    echo chr(0x80 | (($arr[$k] >> 12) & 0x3f));
                                    echo chr(0x80 | (($arr[$k] >> 6) & 0x3f));
                                    echo chr(0x80 | ($arr[$k] & 0x3f));
                                } else {
                                    trigger_error(
                                        'utf8_from_unicode: Codepoint out of Unicode range ' .
                                        'at index: ' . $k . ', value: ' . $arr[$k],
                                        E_USER_WARNING
                                    );

                                    // out of range
                                    return false;
                                }
                            }
                        }
                    }
                }
            }
        }

        $result = ob_get_contents();
        ob_end_clean();

        return $result;
    }
698889
public function fromArray($arr)
    {
        $obj  = $this->getWorkerObject();
        foreach ($arr as $element) {
            $obj->clear();
            $obj->fromArray($element);
            $this->append($obj->toArray());
        }
    }
1179109
protected static function isArrayAssoc($arr)
    {
        $arr = (array)$arr;
        if (array() === $arr) return false;
        return array_keys($arr) !== range(0, count($arr) - 1);
    }
965994
private static function utf8ToUnicode($str)
    {
        $unicode = array();
        $values = array();
        $lookingFor = 1;

        for ($i = 0; $i < strlen($str); $i++ ) {
            $thisValue = ord($str[$i]);

            if ($thisValue < 128) {
                $unicode[] = $thisValue;
            }
            else {
                if (count($values) == 0) {
                    $lookingFor = $thisValue < 224 ? 2 : 3;
                }

                $values[] = $thisValue;

                if (count($values) == $lookingFor) {
                    $number = $lookingFor == 3
                              ? (($values[0] % 16) * 4096) + (($values[1] % 64) * 64) + ($values[2] % 64)
                              : (($values[0] % 32) * 64) + ($values[1] % 64);

                    $unicode[] = $number;
                    $values = array();
                    $lookingFor = 1;
                }
            }
        }

        return $unicode;
    }
344428
public static function toUnicodeCodepoint($char)
    {
        $charCode = false;
        // 7bits, 1 char
        if ((ord($char[0]) & 0x80) == 0x00) {
            $charCode = ord($char[0]);
        } elseif ((ord($char[0]) & 0xe0) == 0xc0) { // 11 bits, 2 chars
            if ((ord($char[1]) & 0xc0) != 0x80) {
                return $charCode;
            }

            $charCode = (
                ((ord($char[0]) & 0x1f) << 6) +
                ((ord($char[1]) & 0x3f))
            );

            if ($charCode < 128) {
                throw new RuntimeException('Illegal UTF-8 input character: ' . $char);
            }
        } elseif ((ord($char[0]) & 0xf0) == 0xe0) { // 16 bits, 3 chars
            if ((ord($char[1]) & 0xc0) != 0x80 ||
                 (ord($char[2]) & 0xc0) != 0x80) {
                return $charCode;
            }
            $charCode = (
                ((ord($char[0]) & 0x0f) << 12) +
                ((ord($char[1]) & 0x3f) << 6) +
                ((ord($char[2]) & 0x3f))
            );

            if ($charCode < 2048) {
                throw new RuntimeException('Illegal UTF-8 input character: ' . $char);
            }
        } elseif ((ord($char[0]) & 0xf8) == 0xf0) { // 21 bits, 4 chars
            if ((ord($char[1]) & 0xc0) != 0x80 ||
                 (ord($char[2]) & 0xc0) != 0x80 ||
                 (ord($char[3]) & 0xc0) != 0x80) {
                return $charCode;
            }

            $charCode = (
                ((ord($char[0]) & 0x07) << 18) +
                ((ord($char[1]) & 0x3f) << 12) +
                ((ord($char[2]) & 0x3f) << 6) +
                ((ord($char[3]) & 0x3f))
            );

            if ($charCode < 65536) {
                throw new RuntimeException('Illegal UTF-8 input character: ' . $char);
            }
        } elseif ((ord($char[0]) & 0xfc) == 0xf8) { // 26 bits, 5 chars
            if ((ord($char[1]) & 0xc0) != 0x80 ||
                 (ord($char[2]) & 0xc0) != 0x80 ||
                 (ord($char[3]) & 0xc0) != 0x80 ||
                 (ord($char[4]) & 0xc0) != 0x80) {
                return $charCode;
            }

            $charCode = (
                ((ord($char[0]) & 0x03) << 24) +
                ((ord($char[1]) & 0x3f) << 18) +
                ((ord($char[2]) & 0x3f) << 12) +
                ((ord($char[3]) & 0x3f) << 6) +
                ((ord($char[4]) & 0x3f))
            );

            if ($charCode < 2097152) {
                throw new RuntimeException('Illegal UTF-8 input character: ' . $char);
            }
        } elseif ((ord($char[0]) & 0xfe) == 0xfc) { // 31 bits, 6 chars
            if ((ord($char[1]) & 0xc0) != 0x80 ||
                 (ord($char[2]) & 0xc0) != 0x80 ||
                 (ord($char[3]) & 0xc0) != 0x80 ||
                 (ord($char[4]) & 0xc0) != 0x80 ||
                 (ord($char[5]) & 0xc0) != 0x80) {
                return $charCode;
            }

            $charCode = (
                ((ord($char[0]) & 0x01) << 30) +
                ((ord($char[1]) & 0x3f) << 24) +
                ((ord($char[2]) & 0x3f) << 18) +
                ((ord($char[3]) & 0x3f) << 12) +
                ((ord($char[4]) & 0x3f) << 6) +
                ((ord($char[5]) & 0x3f))
            );

            if ($charCode < 67108864) {
                throw new RuntimeException('Illegal UTF-8 input character: ' . $char);
            }
        }

        return $charCode;
    }
1293836
public static function unicode_to_utf8($str)
    {
        if (extension_loaded('mbstring')) {
            return preg_replace_callback(
                '/\\\\u([0-9a-fA-F]{4})/',
                function ($match) {
                    return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
                },
                $str
            );
        }

        return $str;
    }
1317715
public static function Deserialize($arr){
		if(is_null($arr))
			return null;
		$res=Array();
		$i=-1;
		$len=sizeof($arr);
		while(++$i<$len)
			$res[$arr[$i]->Key]=$arr[$i]->Value;
		return $res;
	}
1121129
function getTokenFromArray( $arr ) {
    if (isset($arr['access_token']) && $arr['access_token']) {
      $token = array();
      $this->access_token = $token['access_token'] = $arr['access_token'];
      if (isset($arr['refresh_token']) && $arr['refresh_token']) {
        $this->refresh_token = $token['refresh_token'] = $arr['refresh_token'];
      }

      return $token;
    } else {
      return false;
    }
  }
501579
public function json($arr, $out = true)
    {
        $this->setHeader('Content-type', 'application/json');
        $res = json_encode($arr, JSON_UNESCAPED_UNICODE);
        if ($out) {
            $this->send($res);
            return "";
        }
        return $res;
    }
341555
public static function merge2D(array $arr) {
		$args = func_get_args();
		$results = call_user_func_array('array_merge', $args);
		foreach ($results as $key => $value) {
			$temps = array();
			foreach ($args as $val) {
				$temps[] = isset($val[$key]) ? (array)$val[$key] : array();
			}
			$results[$key] = call_user_func_array('array_merge', $temps);
		}
		return $results;
	}
132036
protected function _encodeUtf8Array($aArray)
    {
        $aRet = array();

        foreach ($aArray as $sKey => $mValue) {
            if (!$this->isUtfString($mValue)) {
                $sKey = utf8_encode($sKey);
            }

            if (is_string($mValue)) {
                if (!$this->isUtfString($mValue)) {
                    $mValue = utf8_encode($mValue);
                }
            } elseif (is_array($mValue)) {
                $mValue = $this->_encodeUtf8Array($mValue);
            }

            $aRet[$sKey] = $mValue;
        }

        return $aRet;
    }
1136008
protected static function encodeUnicodeSupplementaryCharactersCallback(array $m)
	{
		$utf8 = $m[0];
		$cp   = (ord($utf8[0]) << 18) + (ord($utf8[1]) << 12) + (ord($utf8[2]) << 6) + ord($utf8[3]) - 0x3C82080;

		return '&#' . $cp . ';';
	}
348995
private static function fromArray($arr, &$result = [], $limit = false, $offset = 1)
    {
        if (is_null($arr)) {
            return $arr;
        }
        if (false === $limit) {
            $limit = strlen($arr) - 1;
            $result = [];
        }
        if ('{}' != $arr) {
            do {
                if ('{' != $arr{$offset}) {
                    preg_match("/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/", $arr, $match, 0, $offset);
                    $offset += strlen($match[0]);
                    $result[] = ('"' != $match[1]{0} ? $match[1] : stripcslashes(substr($match[1], 1, -1)));
                    if ('},' == $match[3]) {
                        return $offset;
                    }
                } else {
                    $innerResult = [];
                    $offset = self::fromArray($arr, $innerResult, $limit, $offset + 1);

                    $result[] = $innerResult;
                }
            } while ($limit > $offset);
        }

        return $result;
    }
658420
public static function trad2simp($str) {
    if (empty($str)) {
      throw new Exception('Argument str cannot be empty');
    }
    $ords = self::utf8ToUnicode($str);
    foreach ($ords as $k => $val) {
      if ($val !== false && array_key_exists($val, self::$trad2simple)) {
        $ords[$k] = self::$trad2simple[$val];
      }
      else {
        $ords[$k] = $val;
      }
    }
    return self::unicodeToUtf8($ords);
  }
406362
private function recursiveUTF8Decode($result)
    {
        if (is_array($result)) {
            foreach ($result as &$value) {
                $value = $this->recursiveUTF8Decode($value);
            }
            return $result;
        } else {
            return utf8_decode($result);
        }
    }
257209
protected static function strContains($str, array $arr)
    {
        foreach ($arr as $a) {
            if (stripos($str, $a) !== false) {
                return true;
            }
        }
        return false;
    }
1160041
public static function from_array($arr)
    {
        $obj = new rcube_message_header;
        foreach ($arr as $k => $v)
            $obj->set($k, $v);

        return $obj;
    }