| px | top | add code | search | signup | login | help |
//
// start of altaebaixa function
<?
/* função que retorna um nome próprio em
Iniciais maiúsculas, exceto as preposições
e, de, da, do, das, dos
this function returns a string with first caracter in uppercase,
excepting the prepositions, because, in some languages they must remain lowercase in name of persons, cities, etc.
BTW, "altaebaixa" means "upperandlowercase"
by Cesar Rocha (csrocha@solar.com.br)
*/
include 'trocaini.fcn';
// change E, e, De, de, etc, according your language
function altaebaixa($umtexto) {
$troca = strtolower($umtexto);
$troca = ucwords($troca);
$troca = trocaini($troca, " E ", " e ");
$troca = trocaini($troca, " De ", " de ");
$troca = trocaini($troca, " Da ", " da ");
$troca = trocaini($troca, " Do ", " do ");
$troca = trocaini($troca, " Das ", " das ");
$troca = trocaini($troca, " Dos ", " dos ");
$altabaixa = $troca;
return $altabaixa;
}
?>
// end of altaebaixa function
//
// This is an aid-function to the first function
//
// start of trocaini function
<?
/* função auxiliar para a função altaebaixa
this is an aid-function to altaebaixa.fcn
*/
function trocaini($wStr,$w1,$w2) {
$wde = 1;
$para=0;
while($para<1) {
$wpos = strpos($wStr, $w1, $wde);
if ($wpos > 0) {
$wStr = str_replace($w1, $w2, $wStr);
$wde = $wpos+1;
} else {
$para=2;
}
}
$trocou = $wStr;
return $trocou;
}
?>
// end of trocaini function
// This is a script to show the usage of the above altaebaixa function
//
//
<?
echo "Teste de Caixa Alta e Baixa<p>";
include 'altaebaixa.fcn';
$nome = "MELÂNIA PRISCYLLA DE OLIVEIRA DOS SANTOS";
$nome2 = "fátima aparecida dos santos e silva";
echo "\$nome originalmente era assim: <B>".$nome."</B><p>";
echo "\$nome2 originalmente era assim: <B>".$nome2."</B><p>";
$novonome = altaebaixa($nome);
$novonome2 = altaebaixa($nome2);
echo "Após passar pela função, ele fica assim: <B>".$novonome."</B><p>";
echo "Após passar pela função, ele fica assim: <B>".$novonome2."</B>";
?>
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.