note 41485 added to function.str-replace

From: Date: Mon, 12 Apr 2004 07:42:20 +0000
Subject: note 41485 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-68007@lists.php.net to get a copy of this message
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); ?> ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41485 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41485&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41485&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#68007) next »