Medium-like Estimated Reading Time

Posted 3 years ago     6267      php

The code is pretty simple. It assumes you read at 200 words per minute. If the text is under 200 words, it’ll just say it’s a one minute read.

function read_time($text){
    $words = str_word_count(strip_tags($text));
    $min = floor($words / 200);
    if($min === 0){
        return 'min read';
    return $min . 'min read';



Math.floor($0.textContent.split(' ').length/230) + " mins read";

$0 is the content of interest.

Please see my snippet for an expanded function with second accuracy here.

You need to be logged in to post comments.

Welcome to Snippet Repo!

Discover, share and save useful code snippets.

Join our community over over 2,000 members! Currently a 48% acceptance rate. Apply for membership →