Skip to content

Instantly share code, notes, and snippets.

@zerosignalproductions
Created March 31, 2014 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zerosignalproductions/9898557 to your computer and use it in GitHub Desktop.
Save zerosignalproductions/9898557 to your computer and use it in GitHub Desktop.
Estimated Reading time in PHP
<?php
$mycontent = $post->post_content; // wordpress users only
$word = str_word_count(strip_tags($mycontent));
$readingRate = 200;
$m = floor($word / readingRate);
$s = floor($word % readingRate / (readingRate / 60));
$est = $m . ' minute' . ($m == 1 ? '' : 's') . ', ' . $s . ' second' . ($s == 1 ? '' : 's');
?>
<p>Estimated reading time: <?php echo $est; ?></p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment