Calculating WPM

Calculates how long an article takes to read based on the number of words and the speed (in minutes) of which they are read.

function calc_wpm($words, $speed)
{    
  $seconds = floor($words / $speed * 60);
  $datetime = new DateTime('@' . $seconds, new DateTimeZone('UTC'));

  return array(
  'days'    => (int) $datetime->format('z'),
  'hours'   => (int) $datetime->format('G'),
  'minutes' => (int) $datetime->format('i'),
  'seconds' => (int) $datetime->format('s')
  );
}
Example

Simply call the calc_wpm function with the number of words and the speed in which they are read and you should be returned with a array with the time that would take for someone to read under those circumstances.

calc_wpm(100, 10); // Array ( [days] => 0 [hours] => 0 [minutes] => 10 [seconds] => 0 )