note 39929 added to function.strtoupper

From: Date: Mon, 16 Feb 2004 02:40:50 +0000
Subject: note 39929 added to function.strtoupper
Groups: php.notes 
Request: Send a blank email to php-notes+get-65195@lists.php.net to get a copy of this message
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); } ?> ---- Manual Page -- http://www.php.net/manual/en/function.strtoupper.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39929 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39929&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39929&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#65195) next »