Estimate Reading Time
I just came across the idea of estimating the time to read content on a website, so I threw together this https://gist.github.com/3253541 based on this idea.
<?php
/**
* Returns an estimated reading time in a string
* idea from @link http://briancray.com/posts/estimated-reading-time-web-design/
* @param string $content the content to be read
* @return string estimated read time eg. 1 minute, 30 seconds
*/
function estimate_reading_time($content) {
$word_count = str_word_count(strip_tags($content));
$minutes = floor($word_count / 200);
$seconds = floor($word_count % 200 / (200 / 60));
$str_minutes = ($minutes == 1) ? "minute" : "minutes";
$str_seconds = ($seconds == 1) ? "second" : "seconds";
if ($minutes == 0) {
return "{$seconds} {$str_seconds}";
}
else {
return "{$minutes} {$str_minutes}, {$seconds} {$str_seconds}";
}
}
Written by Kevin Perrine
Related protips
1 Response
I made a small plugin a while back just for this purpose :)
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#