Last active
May 5, 2021 16:47
-
-
Save tfevens/55eaf238c9225d7533d8c4987a7c35f2 to your computer and use it in GitHub Desktop.
This snippet returns an integer, for the estimated reading time for a piece of text. Think of the avg time on most blog posts.
This file contains 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
Str::macro('readingTime', function (...$text) { | |
$totalWords = str_word_count(implode(" ", $text)); | |
$minutesToRead = round($totalWords / 200); // Avg WPM of adult | |
return (int)max(1, $minutesToRead); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit to @marcelpociot