Title: Wrong math?
Last modified: August 22, 2016

---

# Wrong math?

 *  Resolved [FredTheAnt](https://wordpress.org/support/users/fredtheant/)
 * (@fredtheant)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/wrong-math/)
 * Check out the post linked below. It contains ~922 words. I set the WPM in your
   plugin to 200. That should work out to about 4.6 minutes, yes? If so, any idea
   why the reading time comes to less than 1 minute?
 * [http://www.refactorsaurusrex.com/kindle-fire-hd6-finally-an-e-reader-thats-good-for-technical-books-articles/](http://www.refactorsaurusrex.com/kindle-fire-hd6-finally-an-e-reader-thats-good-for-technical-books-articles/)
 * Thanks!
 * Nick
 * [https://wordpress.org/plugins/timespan/](https://wordpress.org/plugins/timespan/)

Viewing 13 replies - 1 through 13 (of 13 total)

 *  Thread Starter [FredTheAnt](https://wordpress.org/support/users/fredtheant/)
 * (@fredtheant)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/wrong-math/#post-5647440)
 * Couldn’t wait. Debugged it myself. 🙂
 * The `strip_tags` function is removing more text than, I think, you expected it
   to. On the blog post I linked to above, it was truncating everything subsequent
   to the first inline html element included with my blog post. Specifically, it
   returned everything up to ‘At one point I spent something like $50 bucks on a’
   and truncated the rest. The next word in that sentence is encapsulated in an 
   anchor element. My quick fix was to remove all occurrences of `strip_tags` from
   your code. The word counts might be slightly inflated now, but that’s better 
   than severely reduced. There’s probably a better way to address the situation,
   but I’m not a PHP guy. I’ll leave that to you.
 * On a side note, I went ahead and added this:
 * `$full .= $time_in_minutes == 1 ? 'minute' : 'minutes';`
    `$full .= '</p></span
   >';`
 * Maybe in a future release, something like that can be included as well so that
   we see “1 minute” rather than “1 minutes”.
 * – Nick
 *  Plugin Author [paperleaf](https://wordpress.org/support/users/paperleaf/)
 * (@paperleaf)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/wrong-math/#post-5647520)
 * Hey Fred,
    Thanks for pointing this out.
 * So I think what was actually happening was that we were stripping tags off of
   the variable `$content` rather than off of a temp variable, holding the content.
   This caused the content to become a different length than intended, skewing the
   reading numbers.
 * When calculating the word count length in from a WordPress content section, though,
   you need to calculate the word count from the content with the tags pre-stripped.
 * This should all be fixed in the update that was pushed this morning. Again, thank
   you for brining this up.
 * The next question is when did you see the ‘1 minutes’ text occur? Is there anyway
   you could provide the length of the post, and your settings so I can try to duplicate
   this on our test environment? If you can, send this in an email to `keyfer@paper-
   leaf.com`.
 * Thanks again.
 *  Thread Starter [FredTheAnt](https://wordpress.org/support/users/fredtheant/)
 * (@fredtheant)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/wrong-math/#post-5647527)
 * Just tried your fix; didn’t work. :\
 * Not sure I understand why saving `$content` to a temp variable would help? Why
   would you expect different results for…
 *     ```
       $temp = $content;
       $word_count = str_word_count( strip_tags( $temp ) );
       ```
   
 *  versus…
 *     ```
       $word_count = str_word_count( strip_tags( $content ) );
       ```
   
 * ?
 * Both return the same value for `$word_count`, at least when I run it. Do you 
   get different results?
 * Regarding the ‘1 minutes’ thing, your code is hardcoded to show ‘minutes’ (plural)
   by default:
 * `$full .= 'minutes</p></span>';`
 *  Plugin Author [paperleaf](https://wordpress.org/support/users/paperleaf/)
 * (@paperleaf)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/wrong-math/#post-5647563)
 * It seemed as though there was an issue with the `$content` variable, as that’s
   what we were using to output the content. I assumed that it was outputting a 
   shortened version, but it seems that didn’t fix the problem you were having.
 * I’m unsure as to why this is happening on your post. Is there anyway you can 
   send me the full HTML output of your post’s first paragraph, or even write it
   in here? The function `strip_tags` should only be parsing out the HTML elements
   of the post, and leaving the plain text to be counted by `str_word_count`. This
   seems to be working on our test servers here, and we haven’t had this bug come
   up before, so I’d like to dig a little deeper into this.
 * As for the `minutes` question, you are correct that is it hardcoded to show `
   minutes` (plural), but not by default. To show `minutes` rather than `minute`
   it has to pass through this `if` statement: `if ($time_in_minutes < 1)`.
 * Can I ask your exact word count for this specific post you’re talking about? 
   It might help me trouble shoot more if I can recreate the environment locally.
 * Thanks
 *  Plugin Author [paperleaf](https://wordpress.org/support/users/paperleaf/)
 * (@paperleaf)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/wrong-math/#post-5647593)
 * Hey Fred,
 * Please let us know if you’re continuing to have this problem, or if has been 
   solved. If you’re still having this problem, please refer to the last post we’ve
   made.
 * If there isn’t a response in the next week, I’ll mark this as resolved.
 * Thanks!
 *  [Nick](https://wordpress.org/support/users/refactorsaurusrex/)
 * (@refactorsaurusrex)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/wrong-math/#post-5647594)
 * Hey sorry, I’ve been on vacation. I’ll respond as soon as I can.
 *  [Nick](https://wordpress.org/support/users/refactorsaurusrex/)
 * (@refactorsaurusrex)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/wrong-math/#post-5647599)
 * Here’s the raw text of the post in question:
 * [https://gist.github.com/refactorsaurusrex/25ef46797544aa8be7df](https://gist.github.com/refactorsaurusrex/25ef46797544aa8be7df)
 * Sorry for the delay,
 * Nick
 *  [Nick](https://wordpress.org/support/users/refactorsaurusrex/)
 * (@refactorsaurusrex)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/wrong-math/#post-5647617)
 * Hey guys,
 * Any updates on this?
 * Thanks,
 * Nick
 *  Plugin Author [paperleaf](https://wordpress.org/support/users/paperleaf/)
 * (@paperleaf)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/wrong-math/#post-5647618)
 * Hey Nick,
 * Sorry for the delay here! Swamped with client work – we’ll try and get to this
   and get back to you this upcoming week.
 *  Plugin Author [paperleaf](https://wordpress.org/support/users/paperleaf/)
 * (@paperleaf)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/wrong-math/#post-5647619)
 * Hey Nick,
 * Can you try this for me?
 * In your post right now is this line of text:
 * `At one point I spent something like $50 bucks on a <a href="http://www.refactorsaurusrex.
   com/wp-content/uploads/2014/11/AtlasBookStand.jpg" title="Book Stand" class="
   lightbox" data-lightbox-gallery="fancybox-item-01", ">professional book stand
   </a>`
 * Can we change it to this:
    `At one point I spent something like $50 bucks on 
   a <a href="http://www.refactorsaurusrex.com/wp-content/uploads/2014/11/AtlasBookStand.
   jpg" title="Book Stand" class="lightbox" data-lightbox-gallery="fancybox-item-
   01">professional book stand</a>`
 * I think there was a syntax error in the inline-link, which caused the `strip_tags`
   to pull out more than necessary.
 * Let me know if that works.
 *  [Nick](https://wordpress.org/support/users/refactorsaurusrex/)
 * (@refactorsaurusrex)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/wrong-math/#post-5647620)
 * Wow. I cannot believe I missed that. All my internet points to you. That seems
   to solve the problem.
 * Thank you!
 *  Thread Starter [FredTheAnt](https://wordpress.org/support/users/fredtheant/)
 * (@fredtheant)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/wrong-math/#post-5647621)
 * <logged in with old profile to mark thread as resolved>
 *  Plugin Author [paperleaf](https://wordpress.org/support/users/paperleaf/)
 * (@paperleaf)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/wrong-math/#post-5647622)
 * Yes! MOAR INTERNET POINTS!
 * Thanks Nick, happy it all works.

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Wrong math?’ is closed to new replies.

 * ![](https://ps.w.org/timespan/assets/icon.svg?rev=999432)
 * [TimeSpan](https://wordpress.org/plugins/timespan/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/timespan/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/timespan/)
 * [Active Topics](https://wordpress.org/support/plugin/timespan/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/timespan/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/timespan/reviews/)

 * 13 replies
 * 3 participants
 * Last reply from: [paperleaf](https://wordpress.org/support/users/paperleaf/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/wrong-math/#post-5647622)
 * Status: resolved