Ver Mensaje Individual
  #8 (permalink)  
Antiguo 27/12/2007, 20:46
Avatar de Italico76
Italico76
 
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 17 años, 1 mes
Puntos: 292
Re: Detección de Mayúsculas y Minúsculas

Te paso algunas de las funciones que me hice para ver los "grises" (cuando hay un real abuso de mayusculas en un texto) -aca el threshold se llama "umbral"-

<?php

Function resolve_abuse($str){
// Pruebo si hay una sola palabra menor de 9 carcacteres MAC OS X
$evitar=false;
if (!strpos($str, " ") && strlen($str)<=8){
$evitar=true;
}

if (abuse_capitals($str) && !$evitar) {
$str= strtolower($str);
$str[0]=strtoupper($str[0]);
}

return($str);
} // fun

Function abuse_capitals($str){
$umbral =83; // umbral para decidir cuando es abuso de mayusculas

$temp = pesa_letras($str);
//echo $temp;
if ($temp<$umbral){
return (true);
}else{
return (false);
}
}

Function pesa_letras($str){
// MENOS de XX es abuso de mayusculas
$str=trim($str);
$largo=strlen($str);

$peso=0;
for ($i=0;$i<$largo;++$i){
$peso=$peso + ord($str[$i]);
}

if ($largo>0){
return( $peso/$largo);
}
else{
return(100); // todo ok
}

?>
__________________
Salu2!