/** * Upper case the first letter of a word, even if it is a letter with an accent * * @param $word * @author Nicolas Rod */ function ucfirst_special($word) { $word = ucfirst($word); /* * Case of special chars */ $special_chars = array('à' => 'À', 'á' => 'Á', 'â' => 'Â', 'ä' => 'Ä', 'ã' => 'Ã', 'é' => 'É', 'è' => 'È', 'ê' => 'Ê', 'ë' => 'Ë', 'ẽ' => 'Ẽ', 'ì' => 'Ì', 'í' => 'Í', 'î' => 'Î', 'ï' => 'Ï', 'ĩ' => 'Ĩ', 'ò' => 'Ò', 'ó' => 'Ó', 'ô' => 'Ô', 'ö' => 'Ö', 'õ' => 'Õ', 'ù' => 'Ù', 'ú' => 'Ú', 'û' => 'Û', 'ü' => 'Ü', 'ũ' => 'Ũ'); foreach ($special_chars as $min => $maj) { if (StringTool::start_with($word, $min)) { $sub_upper_cased = substr($word, 2); $word = $maj . $sub_upper_cased; break; } } return $word; }
function startsWith($string, $needle) { //return (substr($string, 0, strlen($needle)) == $needle); return StringTool::start_with($string, $needle); }
/** * Ensure a string starts with another given string * * @param $string The string that must start with a leading string * @param $leading_string The string to add at the beginning of the main string if necessary * @return string */ public static function ensure_start_with($string, $leading_string) { if (StringTool::start_with($string, $leading_string)) { return $string; } else { return $leading_string . $string; } }
public static function mb_ucfirst($text) { if (function_exists('mb_substr') && function_exists('mb_strtoupper')) { $letter1 = mb_substr($text, 0, 1); $rest = mb_substr($text, 1); $letter1_uc = mb_strtoupper($letter1); $utext = $letter1_uc . $rest; return $utext; } else { $word = ucfirst($text); /* * Case of special chars */ $special_chars = array('à' => 'À', 'á' => 'Á', 'â' => 'Â', 'ä' => 'Ä', 'ã' => 'Ã', 'é' => 'É', 'è' => 'È', 'ê' => 'Ê', 'ë' => 'Ë', 'ẽ' => 'Ẽ', 'ì' => 'Ì', 'í' => 'Í', 'î' => 'Î', 'ï' => 'Ï', 'ĩ' => 'Ĩ', 'ò' => 'Ò', 'ó' => 'Ó', 'ô' => 'Ô', 'ö' => 'Ö', 'õ' => 'Õ', 'ù' => 'Ù', 'ú' => 'Ú', 'û' => 'Û', 'ü' => 'Ü', 'ũ' => 'Ũ'); foreach ($special_chars as $min => $maj) { if (StringTool::start_with($text, $min)) { $sub_upper_cased = substr($word, 2); $word = $maj . $sub_upper_cased; break; } } return $word; } }
private function get_clean_redirect_prefixes_server() { $cleaned_SERVER = array(); foreach ($_SERVER as $key => $value) { $new_key = $key; while (StringTool::start_with($new_key, 'REDIRECT_')) { $new_key = substr($new_key, strlen('REDIRECT_')); } $cleaned_SERVER[$new_key] = $value; } return $cleaned_SERVER; }
/** * Set the PHP locale and set the CakePHP language * * @param $locale mixed string or array of string * @return string the new current locale */ public static function set_current_locale($locale) { if (isset($locale)) { if (is_string($locale)) { $locale = strtolower($locale); /* * Depending on the server configuration, the locale that the method 'setlocale()' * is waiting for may be different. * * But as the 'setlocale()' can take an array of strings, we try to pass * an array instead of a string */ switch ($locale) { case 'fr': case 'fre': case 'fren': case 'french': case 'fr_ch': case 'fr_fr': case 'fr_ch.utf-8': case 'fr_fr.utf-8': case 'fr-ch': case 'fr-fr': case 'fr-ch.utf-8': case 'fr-fr.utf-8': $locale = array('fr_CH.UTF-8', 'fr_CH', 'fr_FR.UTF-8', 'fr_FR'); break; case 'en': case 'eng': case 'english': case 'en_en': case 'en_us': case 'en_us.utf-8': case 'en_en.utf-8': case 'en-en': case 'en-us': case 'en-us.utf-8': case 'en-en.utf-8': $locale = array('en_US.UTF-8', 'en_US', 'en_EN.UTF-8', 'en_EN'); break; default: $locale = array($locale); break; } } $new_locale = setlocale(LC_ALL, $locale); //debug($new_locale); if (stripos(strtolower($new_locale), 'utf-8') !== false) { header('Content-Type: text/html; charset=UTF-8'); } if (StringTool::start_with(strtolower($new_locale), 'fr_')) { Configure::write('Config.language', "fr"); } elseif (StringTool::start_with(strtolower($new_locale), 'en_')) { Configure::write('Config.language', "en"); } return $new_locale; } }