Calculate the estimated reading time of any given webpage.
You can install the package via composer:
composer require aheenam/estimated-reading-time
The following command returns the rounded number of estimated minutes to read the given text.
<?php
// text with 400 words
$text = \Faker\Factory::create()->words(400, true);
// returns 2
(new EstimatedReadingTime)
->setText($text)
->calculateTime();
In most of the cases in the web, you do not have a plain text but a HTML fragment, but that does not matter. Internally the tags are stripped away when you use setText()
By default the assumption is made that one is able to read 200 words per minute, but you can easily change this config by setting the property $wordsPerMinute
<?php
// text with 400 words
$text = \Faker\Factory::create()->words(400, true);
// returns 1
(new EstimatedReadingTime)
->setWordsPerMinute(400)
->setText($text)
->calculateTime();
Another default configuration is that this package returns a rounded number of minutes. You can though get a exact value as well.
<?php
$text = \Faker\Factory::create()->words(650, true);
// returns 3.25
(new EstimatedReadingTime)
->exactTime(true)
->setText($text)
->calculateTime();
// returns 3
(new EstimatedReadingTime)
->setText($text)
->calculateTime();
Check CHANGELOG for the changelog
To run tests use
$ composer test
If you discover any security related issues, please email [email protected] or use the issue tracker of GitHub.
Aheenam is a small company from NRW, Germany creating custom digital solutions. Visit our website to find out more about us.
The MIT License (MIT). Please see License File for more information.