PHP/String/count chars

Материал из Web эксперт
Перейти к: навигация, поиск

count_chars.php

   <source lang="html4strict">

<?php

  $sentence = "this is a test";
  $chart = count_chars($sentence, 1); 
  foreach($chart as $letter=>$frequency)
     echo "Character ".chr($letter)." appears $frequency times
";

?>

 </source>
   
  


mixed count_chars ( string str [, int mode] ) returns an array containing the letters used in that string and how many times each letter was used.

   <source lang="html4strict">

<?

   $str = "This is a test, only a test, and nothing but a test.";
   $a = count_chars($str, 1);
   print_r($a);

?>

 </source>