Crisam Posted January 24, 2013 Share Posted January 24, 2013 (edited) Hello I am trying to recreate a histogram I made in Java in PHP. The problem is as follows: Make a function that counts the number of string occurences to produce a histogram using PHP. I got a good idea that the [A-Z,a-z and any other characters such as !,. etc] are needed to be included as well. I just would like a HTML output Edited January 24, 2013 by Crisam Quote Link to comment https://forums.phpfreaks.com/topic/273591-getting-a-histogram-to-display-number-of-occurences-of-a-string/ Share on other sites More sharing options...
requinix Posted January 24, 2013 Share Posted January 24, 2013 What string occurrences? What histogram? What about these characters? Included where? HTML output of what? Quote Link to comment https://forums.phpfreaks.com/topic/273591-getting-a-histogram-to-display-number-of-occurences-of-a-string/#findComment-1407990 Share on other sites More sharing options...
Barand Posted January 24, 2013 Share Posted January 24, 2013 do you mean <?php $str = "Now's the time for all good men to come to the aid of the party!"; $counts = array_count_values(str_split(strtoupper($str))); ksort($counts); #unset($counts[' ']); echo '<pre>'; foreach ($counts as $k=>$n) printf ('%s %3d %s<br>', $k, $n, str_repeat('*', $n)); echo '</pre>'; ?> or do you mean something a little more sophisticated? Quote Link to comment https://forums.phpfreaks.com/topic/273591-getting-a-histogram-to-display-number-of-occurences-of-a-string/#findComment-1408002 Share on other sites More sharing options...
Crisam Posted January 24, 2013 Author Share Posted January 24, 2013 $str = $data; $data= array ( ); // I want to be able to write a script that can be reused and display a histogram using a bars or any //shape $max = max($data); echo ''; foreach ($data as $k=>$v) { // display outputs in a table in HTML here } ?> Quote Link to comment https://forums.phpfreaks.com/topic/273591-getting-a-histogram-to-display-number-of-occurences-of-a-string/#findComment-1408028 Share on other sites More sharing options...
Barand Posted January 24, 2013 Share Posted January 24, 2013 I've shown you how to get the values. If you want bars then you will need to create an image using the GD image library functions Quote Link to comment https://forums.phpfreaks.com/topic/273591-getting-a-histogram-to-display-number-of-occurences-of-a-string/#findComment-1408078 Share on other sites More sharing options...
Crisam Posted January 27, 2013 Author Share Posted January 27, 2013 Yes you have thank you. Quote Link to comment https://forums.phpfreaks.com/topic/273591-getting-a-histogram-to-display-number-of-occurences-of-a-string/#findComment-1408484 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.