TrinityTuts Tips

Calculate post read time using PHP

In this post I will explain to you how we can calculate read time of post using PHP. With the help of this function, you can get reading time.

According to the web, the average reading speed is between 230-280 words per minute.

<?php
function getReadTime($content = ''){
    $word = str_word_count(strip_tags($content));
    $m = floor($word / 230);
    $s = floor($word % 230 / (230 / 60));
    $estimateTime = $m . ' minute' . ($m == 1 ? '' : 's') . ', ' . $s . ' second' . ($s == 1 ? '' : 's');

    return $estimateTime;
}

Call this function and use in your project.

Hope this post help you 🙂 .