note 28038 added to function.ucfirst
| From: | ulderico at maber dot com dot br | Date: | Mon, 30 Dec 2002 18:54:39 +0000 |
| Subject: | note 28038 added to function.ucfirst | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-41485@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úsculasIsto É Um Teste ... O É E O Um Não
Devem Ficar MaiúsculasIsto é um Teste ... o é e o um não Devem Ficar Maiúsculas
--
http://www.php.net/manual/en/function.ucfirst.php
http://master.php.net/manage/user-notes.php?action=edit+28038
http://master.php.net/manage/user-notes.php?action=delete+28038
http://master.php.net/manage/user-notes.php?action=reject+28038