/** * Make a string uppercase * * @param string $string The string being uppercased. * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used. * @return string with all alphabetic characters converted to uppercase. * @access public * @static */ function strtoupper($string) { $_this =& Multibyte::getInstance(); $utf8Map = Multibyte::utf8($string); $length = count($utf8Map); $matched = false; $replaced = array(); $upperCase = array(); for ($i = 0; $i < $length; $i++) { $char = $utf8Map[$i]; if ($char < 128) { $str = strtoupper(chr($char)); $strlen = strlen($str); for ($ii = 0; $ii < $strlen; $ii++) { $upper = ord(substr($str, $ii, 1)); } $upperCase[] = $upper; $matched = true; } else { $matched = false; $keys = $_this->__find($char); $keyCount = count($keys); if (!empty($keys)) { foreach ($keys as $key => $value) { $matched = false; $replace = 0; if ($length > 1 && count($keys[$key]['lower']) > 1) { $j = 0; for ($ii = 0, $count = count($keys[$key]['lower']); $ii < $count; $ii++) { $nextChar = $utf8Map[$i + $ii]; if (isset($nextChar) && $nextChar == $keys[$key]['lower'][$j + $ii]) { $replace++; } } if ($replace == $count) { $upperCase[] = $keys[$key]['upper']; $replaced = array_merge($replaced, array_values($keys[$key]['lower'])); $matched = true; break 1; } } elseif ($length > 1 && $keyCount > 1) { $j = 0; for ($ii = 1; $ii < $keyCount; $ii++) { $nextChar = $utf8Map[$i + $ii - 1]; if (in_array($nextChar, $keys[$ii]['lower'])) { for ($jj = 0, $count = count($keys[$ii]['lower']); $jj < $count; $jj++) { $nextChar = $utf8Map[$i + $jj]; if (isset($nextChar) && $nextChar == $keys[$ii]['lower'][$j + $jj]) { $replace++; } } if ($replace == $count) { $upperCase[] = $keys[$ii]['upper']; $replaced = array_merge($replaced, array_values($keys[$ii]['lower'])); $matched = true; break 2; } } } } if ($keys[$key]['lower'][0] == $char) { $upperCase[] = $keys[$key]['upper']; $matched = true; break 1; } } } } if ($matched === false && !in_array($char, $replaced, true)) { $upperCase[] = $char; } } return Multibyte::ascii($upperCase); }
/** * resets the utf8 map array * * @access private */ function __reset() { $_this =& Multibyte::getInstance(); $_this->__utf8Map = array(); }