Created
August 25, 2015 11:15
-
-
Save Beagon/f27051ebedb3d1dd4287 to your computer and use it in GitHub Desktop.
Calculates the time a person needs to read a text.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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