note 28039 added to function.ucwords

From: Date: Mon, 30 Dec 2002 18:56:41 +0000
Subject: note 28039 added to function.ucwords
Groups: php.notes 
Request: Send a blank email to php-notes+get-41486@lists.php.net to get a copy of this message
those who want to capitalise the first letters of the longer words (which can be very helpful in Latin languages as Portuguese, Italian or Spanish)... I've made this handy function... It captalise only the longer words... And the user can set how long is a SMALLWORD. $string = "isto é um teste ... o é e o um não devem ficar maiúsculas"; echo ucfirst($string)."<BR>"; echo ucwords($string)."<BR>"; echo uclongwords($string); function uclongwords($string){ $strlen = strlen($string); $cursor = 0; $wordlen = 0; $first_letter = 0; $i = 0; DEFINE("SMALLWORD", 3); for($i = 0; $i < $strlen; ++$i){ if($string{$i} != " "){ if($wordlen == 0) $first_letter = $i; if(++$wordlen > SMALLWORD){ $return{$first_letter} = strtoupper($return{$first_letter}); } }else{ $wordlen = 0; } $return .= $string{$i}; } return($return); } should produce Isto é um teste ... o é e o um não devem ficar maiúsculas Isto É Um Teste ... O É E O Um Não Devem Ficar Maiúsculas Isto é um Teste ... o é e o um não Devem Ficar Maiúsculas -- http://www.php.net/manual/en/function.ucwords.php http://master.php.net/manage/user-notes.php?action=edit+28039 http://master.php.net/manage/user-notes.php?action=delete+28039 http://master.php.net/manage/user-notes.php?action=reject+28039

« previous php.notes (#41486) next »