fork download
  1. <?php
  2. $texto = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas porttitor non felis quis dignissim. Morbi varius arcu lorem, eget efficitur nibh interdum vitae. Aenean tristique hendrerit diam a consequat. Nunc eleifend dolor ut rhoncus sollicitudin. Suspendisse tincidunt sodales turpis et egestas. Sed maximus libero malesuada lacus tempor, quis placerat nunc varius. Nam eget lectus imperdiet, lobortis mi sit amet, tristique justo. Fusce in felis et erat auctor vehicula quis dapibus libero. In commodo a leo eu eleifend.";
  3.  
  4. $frequencias = array();
  5. $separadores = " .,;:!?/\"'()[]{}\n\r\t";
  6.  
  7. $palavra = strtok($texto, $separadores);
  8. while($palavra !== false) {
  9. if(array_key_exists(strtoupper($palavra), $frequencias)) {
  10. $frequencias[strtoupper($palavra)]++;
  11. } else {
  12. $frequencias[strtoupper($palavra)] = 1;
  13. }
  14. $palavra = strtok($separadores);
  15. }
  16. arsort($frequencias);
  17. print_r($frequencias);
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Array
(
    [QUIS] => 3
    [ET] => 2
    [VARIUS] => 2
    [IN] => 2
    [TRISTIQUE] => 2
    [A] => 2
    [LIBERO] => 2
    [LOREM] => 2
    [ELEIFEND] => 2
    [NUNC] => 2
    [FELIS] => 2
    [EGET] => 2
    [DOLOR] => 2
    [SIT] => 2
    [AMET] => 2
    [LEO] => 1
    [TEMPOR] => 1
    [LACUS] => 1
    [MALESUADA] => 1
    [EGESTAS] => 1
    [SED] => 1
    [MAXIMUS] => 1
    [EU] => 1
    [PLACERAT] => 1
    [COMMODO] => 1
    [JUSTO] => 1
    [VEHICULA] => 1
    [FUSCE] => 1
    [AUCTOR] => 1
    [DAPIBUS] => 1
    [MI] => 1
    [NAM] => 1
    [LECTUS] => 1
    [IMPERDIET] => 1
    [LOBORTIS] => 1
    [ERAT] => 1
    [UT] => 1
    [DIGNISSIM] => 1
    [NON] => 1
    [MORBI] => 1
    [ARCU] => 1
    [EFFICITUR] => 1
    [PORTTITOR] => 1
    [MAECENAS] => 1
    [IPSUM] => 1
    [CONSECTETUR] => 1
    [ADIPISCING] => 1
    [ELIT] => 1
    [NIBH] => 1
    [INTERDUM] => 1
    [SOLLICITUDIN] => 1
    [SUSPENDISSE] => 1
    [TINCIDUNT] => 1
    [SODALES] => 1
    [RHONCUS] => 1
    [CONSEQUAT] => 1
    [VITAE] => 1
    [AENEAN] => 1
    [HENDRERIT] => 1
    [DIAM] => 1
    [TURPIS] => 1
)