PHPackages                             waqarahmed/read-time - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. waqarahmed/read-time

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

waqarahmed/read-time
====================

Get estimated read time of an article. Similar to medium.com's "x min read".

v1.1(4y ago)983MITPHPPHP &gt;=7.2.0

Since Aug 5Pushed 4y ago2 watchersCompare

[ Source](https://github.com/waqar3/read-time)[ Packagist](https://packagist.org/packages/waqarahmed/read-time)[ RSS](/packages/waqarahmed-read-time/feed)WikiDiscussions main Synced yesterday

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Read Time
=========

[](#read-time)

Calculates the read time of an article.

### Output string

[](#output-string)

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

### Features

[](#features)

- 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
------------

[](#installation)

Installation using composer

```
composer require waqarahmed/read-time
```

Usage
-----

[](#usage)

### Static Methods

[](#static-methods)

There are two static methods `minRead(string $text)` and`time(sting $text)`.

### minRead()

[](#minread)

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()

[](#time)

`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
ReadTime::time($text);
```

The output:

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

### Class Methods

[](#class-methods)

Create an instance of the class to use

- translation
- right-to-left language support
- JSON output
- array output

### constructor()

[](#constructor)

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

[](#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

### getTime()

[](#gettime)

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`.

### setTextLanguge()

[](#settextlanguge)

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

[](#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();
```

### Translation

[](#translation)

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

[](#default-property-of-translation)

```
$translation = [
        'min'     => 'min',
        'minute'  => 'minute',
        'minutes' => 'minutes',
        'read'    => 'read',
    ];
```

#### Example translation input

[](#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

[](#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'`

### getJSON()

[](#getjson)

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();
```

outputs:

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

### getArray()

[](#getarray)

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();
```

Outputs:

```
array(6) {
  ["minutes"]=>
  int(2)
  ["time"]=>
  array(2) {
    ["minutes"]=>
    int(2)
    ["seconds"]=>
    int(12)
  }
  ["wordCount"]=>
  int(502)
  ["translation"]=>
  array(4) {
    ["min"]=>
    string(3) "min"
    ["minute"]=>
    string(6) "minute"
    ["minutes"]=>
    string(7) "minutes"
    ["read"]=>
    string(4) "read"
  }
  ["abbreviate"]=>
  bool(true)
  ["wordsPerMinute"]=>
  int(228)
}
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1739d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a5a0f909d0a084c5919b1a73ed0d5707354e4420160b2ecb7acc979f081c02ef?d=identicon)[waqarahmed](/maintainers/waqarahmed)

---

Top Contributors

[![waq-r](https://avatars.githubusercontent.com/u/740101?v=4)](https://github.com/waq-r "waq-r (14 commits)")[![ehsan957](https://avatars.githubusercontent.com/u/1728920?v=4)](https://github.com/ehsan957 "ehsan957 (2 commits)")

---

Tags

articleblogreadtime

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/waqarahmed-read-time/health.svg)

```
[![Health](https://phpackages.com/badges/waqarahmed-read-time/health.svg)](https://phpackages.com/packages/waqarahmed-read-time)
```

###  Alternatives

[bigwhoop/sentence-breaker

Sentence boundary disambiguation (SBD) - or sentence breaking - library written in PHP.

42132.3k](/packages/bigwhoop-sentence-breaker)[j0k3r/graby-site-config

Graby site config files

23365.8k3](/packages/j0k3r-graby-site-config)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
