Created
January 15, 2024 16:33
-
-
Save dhanar98/d3e65856261a3b46a6c9a1cf9ac1758b to your computer and use it in GitHub Desktop.
Reading Time in Blog Post Using laravel Str:wordCount() Function In Helper
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
<?php | |
# Filename : app/helpers.php | |
use Illuminate\Support\Str; | |
if (!function_exists('calculateReadingTime')) { | |
function calculateReadingTime($content) | |
{ | |
$word_count = Str::wordCount($content); | |
$reading_time = ceil($word_count / 200); | |
if ($reading_time == 1) { | |
$timer = " minute"; | |
} else { | |
$timer = " minutes"; | |
} | |
$total_reading_time = $reading_time . $timer; | |
return $total_reading_time; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment