kaveman50 Posted October 22, 2009 Share Posted October 22, 2009 Hello guys. Does anyone know how to input a sentence, and then output how many of each character was used in the sentence? My sentence will be, "The green fox jumped over the yellow lion." Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted October 22, 2009 Share Posted October 22, 2009 $sentence = "The green fox jumped over the yellow lion."; $sentenceArray = str_split($sentence); print_r(array_count_values($sentenceArray)); Quote Link to comment Share on other sites More sharing options...
kaveman50 Posted October 24, 2009 Author Share Posted October 24, 2009 Thanks Mark. By any chance, do you know how to output the A's as just one array? (Instead of displaying the upper and lowercase separately.) Quote Link to comment Share on other sites More sharing options...
Alex Posted October 24, 2009 Share Posted October 24, 2009 Use strtolower() to convert the string to all lower-case before array_split(). eg $setenceArray = str_split(strtolower($sentence)); Quote Link to comment Share on other sites More sharing options...
kaveman50 Posted October 25, 2009 Author Share Posted October 25, 2009 Thanks Alex Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.