Created
May 5, 2021 11:30
-
-
Save nezaboravi/ee7e0b9ef599315f347107a4047c1534 to your computer and use it in GitHub Desktop.
Small macro for a read duration, laravel
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
Str::macro('readDuration', function( ...$text) { | |
$totalWords = str_word_count(implode(' ', $text)); | |
$minutesToRead = round($totalWorlds / 200); | |
return (int) max(1, $minutesToRead); | |
}); | |
echo Str::readDuration($post->text) . ' min read'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment