note 28039 deleted from function.ucwords by victor
| From: | victor@php.net | Date: | Sat, 12 Jun 2004 21:05:58 +0000 |
| Subject: | note 28039 deleted from function.ucwords by victor | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-70987@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ú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