PHP Classes

PHP Read Time: Estimate the time for a person to read an article

Recommend this page to a friend!
  Info   View files Documentation   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 95 All time: 9,845 This week: 673Up
Version License PHP version Categories
read-time 1.0.1GNU General Publi...7PHP 5, Statistics, Text processing, B...


This class can estimate the time for a person to read an article.

It takes the text of an article as a parameter and returns the length of time that it would take a person to read that text. It supports processing text in different languages and text that people should read from right to left.

The class can return the read time as an array with the count of the minutes and seconds or a string that expresses the read time in English.

It can also return the read time in other languages if the class gets the translations of the text messages used to format the read time string.

Innovation Award
PHP Programming Innovation award nominee
July 2021
Number 5

Prize: One year server license IP to country, region, city, latitude, longitude, ZIP code, time zone, area code database
Many users like to read blogs about interesting topics, but often they do not have much time to read long articles.

This class can estimate the time that an article could take to be read by an average user.

This way, sites can show the estimated read time to help users decide if they have the time to read the article when they look at it for the first time or leave it later.

Manuel Lemos
Picture of Waqar Ahmed
Name: Waqar Ahmed is available for providing paid consulting. Contact Waqar Ahmed .
Classes: 3 packages by
Country: United Kingdom
Age: ???
All time rank: 2620120 in United Kingdom
Week rank: 289 Up11 in United Kingdom Up
Innovation award
Innovation award
Nominee: 1x


Read Time

Calculates the read time of an article.

Output string

e.g: x min read or 5 minutes read.


  • Multilingual translations support.
  • Static to get simple abbreviated output string in English.
  • Static method to get the integer value of the number of minutes required to read the given text.
  • Multilingual and right-to-left language support.
  • Support for Array output
  • Support for JSON output


Installation using composer

composer require waqarahmed/read-time


Static Methods

There are two static methods minRead(string $text) andtime(sting $text).


Use this method for a simple x min read message. It returns a rounded minutes number with a min read message.

$text = str_repeat('ad bc ', 251); //502 words in $text
echo ReadTime::minRead($text);

The output:

2 min read


time() method returns an array of the number of minutes and seconds required to read the given $text.

$text = str_repeat('ad bc ', 251); //502 words in $text

The output:

['minutes' => 2, 'seconds' => 12]

Class Methods

Create an instance of the class to use - translation - right-to-left language support - JSON output - array output


The Constructor takes and sets these parameters:

public function __construct(
  string $text, 
  array $translation = null, 
  bool $abbreviate = true, 
  bool $rtl = false, 
  string $language = null,
  int $wordsPerMinute = 228

#### Class defaults - $wordsPerMinute default value is 200 - $rtl language direction right-to-left is false by default - $translation default is null class outputs the English language by default - $abbreviate Abbreviate the word 'minute/minutes' to 'min' is true by default


After initiating a new class object, call the getTime() method to get the result. Example: 4 minutes read or 1 minute read or abbreviated 4 min read.


Reading time of different languages vary significantly (S. Klosinski, K. Dietz). Class method setTextLanguage() has estimated reading times of 17 languages taken from this study.

Reference: "Standardized Assessment of Reading Performance: The New International Reading Speed Texts IReST"

Language (iso-code) Words-per-minutes

Arabic (ar) 138, Chinese (zh) 158, Dutch (nl) 202, English (en) 228, Finnish (fi) 161, French (fr) 195, German (el) 179, Hebrew (he) 187, Italian (it) 188, Japanese (jp) 193, Polish (pl) 166, Portoguese (pt) 181, Russian (ru) 184, Slovenian (sl) 180, Spanish (es) 218, Swedish (sv) 199, Turkish (tr) 166.

English is the default language. Set different languages by passing two letters (ISO 639-1) language codes to the setTextLanguag() method.

An example: Setting Turkish as the input language.

 $text = str_repeat('ad bc ', 251); //502 words in $text
 $result = new ReadTime($this->generateText(), ['minute' => 'dakika', 'minutes' => 'dakika', 'read' => 'okuman'], false, false, 'tr');
 echo $result->getTime();


Pass translation array to the class to set the translations of the words: minute, minutes, min and read. A passed array must be an associative array with any number of translation strings.

Default property of $translation

$translation = [
        'min'     => 'min',
        'minute'  => 'minute',
        'minutes' => 'minutes',
        'read'    => 'read',

Example translation input

$text = str_repeat('ad bc ', 251); //502 words in $text
$result = new ReadTime($this->generateText(), ['minute' => 'minuto', 'minutes' => 'minutos', 'read' => 'leer'], false);
echo $result->getTime();

The Spanish translated output: 2 minutos leer.

Right-to-Left Language Translation

Set $rtl property to true and pass $translation of languages written right-to-left.

$text = str_repeat('ad bc ', 251);
$result = new ReadTime($this->generateText(), ['minute' => '?????', 'minutes' => '?????', 'read' => '??????'], false, true);
echo $result->getTime();

Persian translated output: '?????? ????? 2'


Method to get JSON output of claculated read time and class properties.

A class instance with default properties outputs:

$text = str_repeat('hello world ', 251);
$result = new ReadTime($text);
echo $result->getJSON();


    "minutes": 2,
    "time": {
        "minutes": 2,
        "seconds": 12
    "wordCount": 502,
    "translation": {
        "min": "min",
        "minute": "minute",
        "minutes": "minutes",
        "read": "read"
    "abbreviate": true,
    "wordsPerMinute": 228


Method to get array output of calculated read time and instance properties. A class instance with default properties:

$text = str_repeat('hello world ', 251);
$result = new ReadTime($text);
echo $result->getArray();


array(6) {
  array(2) {
  array(4) {
    string(3) "min"
    string(6) "minute"
    string(7) "minutes"
    string(4) "read"

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Files folder imagetests (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file readTime.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file readTimeTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:9,845
This week:673Up