note 108686 added to function.strtolower

From: Date: Thu, 17 May 2012 17:46:46 +0000
Subject: note 108686 added to function.strtolower
Groups: php.notes 
Request: Send a blank email to php-notes+get-188038@lists.php.net to get a copy of this message
Everyone knows that strtolower/strtoupper does not translate cyrillic charactes (cp1251 code page). But I just was surprised that strtolower works twice(!) slower that translating characters with "strtr()". Here is what I use to translate cyrillic (works for Russian, Ukrainian, Belorussian and cyrillic balcan languages, like Serbian etc): // Arrays (REMOVE THE LINE BREAKS! THIS NOT WON'T BE POSTED WITH SUCH LONG LINES!) $chars_hi = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯЁЂЃЄЅІЇЈЉЊЋЌЎЏҐ'; $chars_lo = 'abcdefghijklmnopqrstuvwxyz абвгдежзийклмнопрстуфхцчшщъыьэюяёђѓєѕіїјљњћќўџґ'; // functions function uppercase($s) { global $chars_hi, $chars_lo; return strtr($s, $chars_lo, $chars_hi); } function lowercase($s) { global $chars_hi, $chars_lo; return strtr($s, $chars_hi, $chars_lo); } Remember, it works TWICE FASTER than strtoupper/strtolower! So maybe someone will would like to translate the arrays for another code pages different than cp1251 ---- Server IP: 77.88.252.46 Probable Submitter: 91.200.180.180 ---- Manual Page -- http://www.php.net/manual/en/function.strtolower.php Edit -- https://master.php.net/note/edit/108686 Del: integrated -- https://master.php.net/note/delete/108686/integrated Del: useless -- https://master.php.net/note/delete/108686/useless Del: bad code -- https://master.php.net/note/delete/108686/bad+code Del: spam -- https://master.php.net/note/delete/108686/spam Del: non-english -- https://master.php.net/note/delete/108686/non-english Del: in docs -- https://master.php.net/note/delete/108686/in+docs Del: other reasons-- https://master.php.net/note/delete/108686 Reject -- https://master.php.net/note/reject/108686 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188038) next »