Skip to content

Instantly share code, notes, and snippets.

@Beagon
Created August 25, 2015 11:15
Show Gist options
  • Select an option

  • Save Beagon/f27051ebedb3d1dd4287 to your computer and use it in GitHub Desktop.

Select an option

Save Beagon/f27051ebedb3d1dd4287 to your computer and use it in GitHub Desktop.
Calculates the time a person needs to read a text.
<?php
$text = "Yes hello, my name is hans.";
$content = $text;
//Defaults
$wordsPerMinute = (isset($wordsPerMinute) ? $wordsPerMinute : 180); //The average adult reads prose text at 250 to 300 words per minute. While proofreading materials, people are able to read at 200 wpm on paper, and 180 wpm on a monitor.
$charsPerWord = (isset($charsPerWord) ? $charsPerWord : 5); //Characters per minute (CPM) are WPM times five, so that 20 WPM are 100 CPM.
//Calculated
$charsPerMinute = $wordsPerMinute * $charsPerWord;
// Strip content from HTML and get content length
$strippedContent = html_entity_decode($content);
$contentLength = strlen($strippedContent);
//Calculate reading time
$readingTime = $contentLength / $charsPerMinute;
return round($readingTime);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment