note 41485 deleted from function.str-replace by nlopess

From: Date: Mon, 12 Apr 2004 16:39:37 +0000
Subject: note 41485 deleted from function.str-replace by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-68025@lists.php.net to get a copy of this message
Note Submitter: webmaster __AT__ digitalanime __DOT__ nl ---- In adition to: kerxen at caramail dot com Eddy Cingala. Defining that array two times, can't be good... Well? Better way to do this, is using ONE function and an extra parameter. <?php define('ACCENTS_TO_LOWER', 1); define('ACCENTS_TO_UPPER', 2); function accentschangecase($text, $type) { $lower = array ( 'à','á','â','ã','ä','å','æ','ç', 'è','é','ê','ë','ì','í','î','ï', 'ð','ñ','ò','ó','ô','õ','ö','÷', 'ø','ù','ü','ú','þ','ÿ' ); $upper = array ( 'À','Á','Â','Ã','Ä','Å','Æ','Ç', 'È','É','Ê','Ë','Ì','Í','Î','Ï', 'Ð','Ñ','Ò','Ó','Ô','Õ','Ö','×' 'Ø','Ù','Ü','Ú','Þ','ß' ); if($type == ACCENTS_TO_LOWER) { $text = str_replace($upper, $lower, $text); $text = strtolower($text); } elseif($type == ACCENTS_TO_UPPER) { $text = str_replace($lower, $upper, $text); $text = strtoupper($text); } else { // hey, that's not good.. trigger_error('Invalid type specified for function ' __FUNCTION__, E_USER_WARNING); } return $text; } $mytext = 'áétiýuisfreteýtry;t;;try;yÁ"SFDËRÜIOÏIÜuióuióuIOÜIO^^ÎÔ'; echo accentschangecase($mytext, ACCENTS_TO_UPPER); echo accentschangecase($mytext, ACCENTS_TO_LOWER); ?>

« previous php.notes (#68025) next »