Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Läsbarhetsindex ( LIX )
- * Swedish Readability Calculator
- *
- * @author Kenth Hagström
- * @version 1.0
- * @license GPL
- * @param $text string
- * @param $periods array
- **/
- function lix( $text, $periods = array( '.', '!', '?', ':' ) )
- {
- // Remove HTML tags from the text content
- $text = strip_tags( $text );
- // Get all words from the text and count 'em
- $all_words = str_word_count( $text, 2 );
- $total_words = count( $all_words );
- // Determine the number of sentences
- $total_sentences = 0;
- foreach( $periods as $punctuation )
- {
- $total_sentences += substr_count( $text, $punctuation );
- }
- // Get the number of long words, ie words longer than 6 characters
- $long_words = 0;
- foreach( $all_words as $word )
- {
- if( strlen( $word ) > 6 )
- {
- $long_words++;
- }
- }
- // Some basic math, http://sv.wikipedia.org/wiki/LIX
- $average_sentence_length = $total_words / $total_sentences;
- $part_long_words = 100 * ( $long_words / $total_words );
- $lix = $average_sentence_length + $part_long_words;
- return $lix;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement