Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/10/2009, 19:33
Avatar de sinderell
sinderell
 
Fecha de Ingreso: octubre-2009
Mensajes: 10
Antigüedad: 15 años, 6 meses
Puntos: 0
Contar letras frecuentes

Hola, en base a un scipt anterior quiero hacer un codigo que me diga los caracteres que hay en un texto y cuantas veces se repite cada uno.
ejemplo
a->5
b->4
c->8
etc...
Este es mi codigo, pero ala hora de hacer el foreach me sale error en el arreglo,
me podrian ayudar xfa??


Código PHP:
$str file_get_contents('archivo2.txt');
 
$str trim($str);
 
$str preg_replace("/\s\s+/"' '$str);
$str strtolower($str);

echo 
"Hay "$count=strlen($str). " letras: "."<br>";

echo 
'<table><tr><th>letra</th></tr>';
//AQUI ES DONDE HAGO EL FOREACH PARA CONTAR CUANTAS VECES SE REPITE CADA CARACTER
for($i=0;$i<strlen($str);$i++)
{
    
//echo '<tr><td>' . $str[$i] . '</td></tr>'; //qui ya me separa las letras
    
if (! array_key_exist($str$miarray))$dd[$one]= 1;
    else 
$add[$one] +=1;
}




echo 
'</table>'
Gracias de antemano!!