Skip to content

Instantly share code, notes, and snippets.

@nezaboravi
Created May 5, 2021 11:30

Revisions

  1. nezaboravi created this gist May 5, 2021.
    8 changes: 8 additions & 0 deletions ReadDuration
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    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';