note 28038 deleted from function.ucfirst by didou
| From: | didou@php.net | Date: | Sun, 18 May 2003 02:40:37 +0000 |
| Subject: | note 28038 deleted from function.ucfirst by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-48347@lists.php.net to get a copy of this message | ||
Note Submitter: ulderico@maber.com.br
----
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