Home API Count Sentences, Words, and Syllables to Return a Flesch Reading Ease Score

Count Sentences, Words, and Syllables to Return a Flesch Reading Ease Score


We manage the learning management of a number of business and often get requests that go beyond the scope of most packaged learning systems – including our own. One of our customers asked if we could count assess all test answers, survey answers, and emails (most importantly) for a Flesch Reading Ease score. Measuring the quality of an individual’s writing was an efficient means of scoring and measuring the improvement of a particular student over time. The idea was that it didn’t matter where and how writing material found its way to faculty, incoming text would always be scored (in context).

The Flesch Reading Ease formula was first developed in 1943 by Rudolf Flesch in his PhD dissertation, Marks of a Readable Style. The early works of Fletch have found their way into two formulas that are most often applied to assess general readability – the Reading Ease score and the The Flesch–Kincaid formula. The former algorithm returns a score from 0 to 100, with 0 equivalent to a college graduate and 100 equivalent to the 5th grade. The latter formula presents a score as a U.S. grade level, making it easier for teachers, parents, librarians, and others to judge the readability level of various books and texts.

The Flesch Reading Ease score is so ubiquitous that a number of U.S states requires that insurance policies be written with a score that equates to a 4th grade level, and publishers have adopted score-testing to increase their readership – generally aiming for a score of 50 or higher (in comparison to academic and scientific papers that most often score lower than 30).

Count Sentences, Words, and Syllables to Return a Flesch Reading Ease Score

Flesch Reading Ease Scale (Source: Wikipedia)

The Flesch–Kincaid score was developed in 1975 alongside the US Navy, and they later adopted the score to assess incoming cadets, internal forms, and text book readability. The score returns a U.S grade level approximation (adding a value of 5 to the result returns the approximate age of an individual in that grade).

No formula is entirely accurate… although the Flesch–Kincaid formula has withstood the test of time and is said to correlate with a score of 0.91 when measured again more traditional reading assessments.

Used in Marketing and Blogging

When you write marketing copy, sales copy, or an article on your website, you should generally aim for a Flesch Reading Ease score of around 60 so your efforts appeal to the largest readership. While there’s a number of WordPress plugins that will make an attempt to score your article readability, few (if any) will return the result a graded results to your website’s front-end… and none of them are overly accurate.

✓ Example Usage
You might choose to return a readability score for each article on your website the same way tutorials are graded from beginner, intermediate, and advanced.

It’s unknown if search engine algorithms apply any readability assessment to pages. However, from a holistic SEO point-of-view, it can’t be ignored.

Flesch Reading Formulas

The Flesch Reading Ease and Flesch–Kincaid Grade Level algorithms are as follows:

Flesch Reading Ease

In the Flesch Reading-Ease Test (FRES). Higher scores indicate material that is easier to read; lower numbers mark passages that are more difficult to read. It’s the Flesch formula that is applied to our example results below.

`206.835 – 1.015 (text{total words} / text{total sentence}) – 84.6 (text{total syllables} / text{total words})`

Flesch–Kincaid Grade Level

The “Flesch–Kincaid Grade Level Formula” presents a score as a U.S. grade level.

`0.39 (text{total words} / text{total sentence}) + 11.8 (text{total syllables} / text{total words}) – 15.59`

There are other readability formulas that are often used in addition to those above; they’re reproduced below.

PHP Considerations

To assess the Flesch Reading Ease score, we require the total words, total sentences, and total syllables in a string… with the latter presenting the most significant hurdle.

First, to determine the number of sentences in a string of text, the following expression may be used:

We’ll clean the text to retain only words and numbers (we’re yet to receive a definitive answer on how numbers should be used).

PHP’s str_word_count() function can be used to return an array of words. We use this array to count the number of words in a string, and then we iterate over all the values to determine the number of syllables in each.

To determine the number of syllables in a word is tricky. After trying a few PHP functions (none of which we could rely upon), we landed upon Text-Statistics – a library hosted on Github. The library is good but, not unlike some of the functions we wrote ourselves, wouldn’t come close to returning the required accuracy. The syllable count is extremely important because of the significant impact it might have upon the Flesch score when erroneous data is returned. We determined that the only way of efficiently ensuring accurate results was to maintain a database of words and their syllable count.

An API was the logical means of returning data to our clients that required it (this also makes maintaining an accurate dictionary a crowd-sourced effort).

We accept three requests; one that requires a basic word => count be returned, another with the syllable count, and a last one with other data (such as vowel and consonant count for each word). Default usage returns only the count. The array that returns the word and syllables looks a little like this:

If a word isn’t found in our database, it is recorded for manual inclusion. It’s only if a word isn’t included in our dictionary that we’ll apply a less-efficient means of determining the syllable count via a PHP algorithm.

API Endpoint: http://api.beliefmedia.com/readability/api.php. A POST request expects at least 2 parameters: apikey and message.

A sample function to submit post is as follows:

A function to return the array should be used to check for errors and valid JSON (omitted for the sake of the example).

The returned JSON data unfolds into an array that looks something like this:

The code of 200 simply means we process your request. A returned error of anything other than 200 means that no result is returned. The final result should be cached so values might be retrieved (and displayed) if required.

WordPress Function

Note: Because of the nuisance processing overhead associated with each request, we only make the API available to our clients.

The WordPress function will cache the result for just 5 minutes if saving a draft. Since the syllable dictionary will evolve over time, a post when published will cache the result for only 60 days (a fresh request is made periodically to return a more reliable score over time).

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

Note: The beliefmedia_post_readability function is also required.


To return a flesch score for an entire post, use the shortcode of [fleschscore].

This page is a really bad example because of the technical nature of the subject and, as such, returns a Flesch score of around 45. The problem with making attempts to score articles like this one (and lots of other tutorial-type posts) is that they’re far from the typical texts intended to be scrutinized and scored – they’re just far too removed from the typical text required to assess literacy (as determined by the simple formula). For this reason, you might consider scoring individual paragraphs by wrapping your text in opening and closing [flesch] tags. For the sake of the example we simply tack the result on the end of a paragraph as follows (in real world use you’ll record the result and use it elsewhere): Flesch Readability Score: 42.59.

The sample function to return what we’ve described above is as follows:

Our plugin provides an option to include a score for every post in your WP publish META box.


  • If you’re after a vowel and/or consonant count, the following expression will do the job (there’s probably more efficient ways of doing so).

  • Processing posts with code is problematic because the readability algorithm assesses the complexity of a sentence without discriminating against any of the text. For that reason we remove anything between pre and code tags, and HTML. How the inclusion of numbers is used for the purpose of the assessment seems to vary from one organisation to another. Consider the three-syllable word “29th” – do we include this in our count? Should titles and headings be considered a sentence? The existing web tools seemingly make their own interpretations meaning that scoring on one tool rarely matches that of another.
  • We include numbers in the word count and generally exclude them from the syllable count. To find the balance we were happy with we turned to Microsoft Office and compared our count to theirs when measured against a full copy of Harry Potter (we matched the novel assessment with 98.4% accuracy). This comparison required that we included a large number of very bizarre words to our dictionary! For comparison, the premium service Readable returns 84 percent accuracy.
  • As noted above, Microsoft Office will return a Flesch and other scores. Navigate to File -> Options -> Proofing and tick the box that says “Show Readability Statistics“. Select “Spelling & Grammar” when writing to see the results.

Count Sentences, Words, and Syllables to Return a Flesch Reading Ease Score

Flesch Readability in Microsoft Office

  • We make attempts to remove anything other than the necessary text required to return a score. It might be prudent to exclude text, code, or anything else you don’t want assessed.
  • For those interested, the math formulas on this page were generated with Mathjax.
  • Our tool scores word documents, PDF documents, and bulk uploads (in addition to numerous other features). It’s likely we’ll turn it into a report-to-email service after our dictionary is more comprehensive (at the time of writing it’s at 75,000 words).
  • We won’t stop working on improving our algorithms!
  • Click the “Show More Readability Formulas” blind below to show additional readability options. Most are returned in our API data.


Clients should be logged in to download this plugin.

■ ■ ■

[blind text=”Show More Readability Formulas”]

Additional Readability Formulas

Coleman–Liau Index

The Coleman–Liau index is a readability test designed by Meri Coleman and T. L. Liau to gauge the understandability of a text. It outputs an approximate U.S. grade level thought necessary to comprehend the text. From Wikipedia, “The Coleman–Liau index was designed to be easily calculated mechanically from samples of hard-copy text. Unlike syllable-based readability indices, it does not require that the character content of words be analyzed, only their length in characters. Therefore, it could be used in conjunction with theoretically simple mechanical scanners that would only need to recognize character, word, and sentence boundaries, removing the need for full optical character recognition or manual keypunching”.

`CLI = 0.0588L – 0.296S – 15.8`

L is the average number of letters per 100 words and S is the average number of sentences per 100 words.

Gunning fog index

In linguistics, the Gunning fog index is a readability test for English writing. The index estimates the years of formal education a person needs to understand the text on the first reading. A fog index of 12 requires the reading level of a U.S. high school senior (around 18 years old). The test was developed by Robert Gunning, an American businessman, in 1952.

The Gunning fog index is calculated with the following algorithm:

  1. Select a passage (such as one or more full paragraphs) of around 100 words. Do not omit any sentences;
  2. Determine the average sentence length. (Divide the number of words by the number of sentences.);
  3. Count the “complex” words: those with three or more syllables. Do not include proper nouns, familiar jargon, or compound words. Do not include common suffixes (such as -es, -ed, or -ing) as a syllable;
  4. Add the average sentence length and the percentage of complex words; and
  5. Multiply the result by 0.4.

The complete formula is:

`0.4 [(text{words} / text{sentence}) + 100 (text{complex words} / text{words})]`

SMOG (Simple Measure of Gobbledygook)

The SMOG grade is a measure of readability that estimates the years of education needed to understand a piece of writing. SMOG is an acronym for Simple Measure of Gobbledygook. SMOG is widely used, particularly for checking health messages. A 2010 study published in the Journal of the Royal College of Physicians of Edinburgh stated that “SMOG should be the preferred measure of readability when evaluating consumer-oriented healthcare material.” The study found that “The Flesch-Kincaid formula significantly underestimated reading difficulty compared with the gold standard SMOG formula.”

The SMOG grade yields a 0.985 correlation with a standard error of 1.5159 grades with the grades of readers who had 100% comprehension of test materials. The result is returned by counting the words of three or more syllables in three 10-sentence samples, estimate the count’s square root (from the nearest perfect square), and add 3.

To calculate SMOG

  1. Count a number of sentences (at least 30)
  2. In those sentences, count the polysyllables (words of 3 or more syllables).
  3. Calculate using the following formula:

`text{grade} = 1.0430 sqrt(text{number of polysyllables} times text{30} / text{number of sentences}) + 3.1291`

This version (sometimes called the SMOG Index) is more easily used for mental math:

SMOG conversion tables compiled by Harold C. McGraw are slightly inaccurate because they are based on the approximate formula. Furthermore, tables for texts of fewer than 30 sentences are statistically invalid, because the formula was normalized on 30-sentence samples.

Automated Readability Index

Designed to assess the readability of electric typewriters, the automated readability index (ARI) is a readability test for English texts, designed to gauge the ‘understandability’ of a text. It produces an approximate representation of the US grade level needed to comprehend the text.

`4.71 (text{characters} / text{words}) + 0.5 (text{words} / text{sentences}) -21.43`

Fry Readability Formula

The Fry readability formula (or Fry readability graph) is a readability metric for English texts, developed by Edward Fry. The grade reading level (or reading difficulty level) is calculated by the average number of sentences (y-axis) and syllables (x-axis) per hundred words. These averages are plotted onto a specific graph; the intersection of the average number of sentences and the average number of syllables determines the reading level of the content.

Count Sentences, Words, and Syllables to Return a Flesch Reading Ease Score


The formula and graph are often used to provide a common standard by which the readability of documents can be measured. It is sometimes used for regulatory purposes, such as in healthcare, to ensure publications have a level of readability that is understandable and accessible by a wider portion of the population.


Short URL for this post: http://shor.tt/2nPH


Please enter your comment!
Please enter your name here