note 39929 deleted from function.strtoupper by derick

From: Date: Tue, 30 Aug 2005 11:07:07 +0000
Subject: note 39929 deleted from function.strtoupper by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-94397@lists.php.net to get a copy of this message
Note Submitter: markku dot uttula at disconova dot com ---- Martine's note is a good one. Taking you have mbstring compiled in, which many don't. It also seems to be missing from (at least) the Win32 binary release (which is understandable). Since this is a problem with many languages, native one of yours truly included, I and a co-worker spent some time with this thing and came up with the following - pretty much same sort of thing many others appear to have thought out earlier. It's the fastest we could come up with (which is extreamely important if you need to use these a lot on a heavily used system), and we sincerely hope it's of use to somebody. <?php define( "UC_CHARS", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕ֌؊ÙÚÛÜݎÞ" ); // If you need more, add define( "LC_CHARS", "àáâãäåæçèéêëìíîïðñòóôõöœøšùúûüýžþ" ); // If you need more, add define( "WORD_SEPARATORS", chr(9).chr(10).chr(11).chr(12).chr(13).chr(32) ); function strtolower2($value) { return ( strtolower( strtr( $value, UC_CHARS, LC_CHARS ) ) ); } function strtoupper2($value) { return ( strtoupper( strtr( $value, LC_CHARS, UC_CHARS ) ) ); } function ucfirst2($value) { return ( strtoupper2( substr( $value, 0, 1 ) ).strtolower2( substr( $value, 1, strlen( $value ) ) ) ); } function ucwords2( $value ) { $upper = strtoupper2( $value ); $value = ucfirst2( $value ); $word_separators = WORD_SEPARATORS; $len = strlen( $value ) - 1; for ( $i = 0; $i < strlen( $word_separators ); $i++ ) { $separator = $word_separators[$i]; $pos = -1; while ( $pos !== false ) { $pos = strpos( $value, $separator, ( $pos + 1 ) ); if ( ( $pos !== false ) && ( $pos < $len ) ) { $value[ ( $pos + 1 ) ] = $upper[ ( $pos + 1 ) ]; } } } return ($value); } ?>

« previous php.notes (#94397) next »