Last active
May 3, 2023 13:00
-
-
Save Velman04/7b33c34e572a28d8749d41ab22a568bb to your computer and use it in GitHub Desktop.
Text reading time | Время чтения текста
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
public function textReadingTime($text, $wpm = 120, $pause = 0.5): int | |
{ | |
preg_match_all('/\w+/u', $text, $words); | |
$wordCount = count($words[0]); | |
$totalPauses = substr_count($text, '.') | |
+ substr_count($text, '!') | |
+ substr_count($text, '?'); | |
$totalPauseTime = $totalPauses * $pause; | |
$readingTime = ($wordCount / $wpm) * 60 + $totalPauseTime; | |
return round($readingTime); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment