SHARE
TWEET

LIX - Swedish Readability Calculator

keha76 Aug 24th, 2012 189 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  *    L√§sbarhetsindex ( LIX )
  4.  *    Swedish Readability Calculator
  5.  *
  6.  *    @author Kenth Hagstr√∂m
  7.  *    @version 1.0
  8.  *    @license GPL
  9.  *    @param $text string
  10.  *    @param $periods array
  11. **/
  12. function lix( $text, $periods = array( '.', '!', '?', ':' ) )
  13. {
  14.         // Remove HTML tags from the text content
  15.         $text = strip_tags( $text );
  16.  
  17.         // Get all words from the text and count 'em
  18.         $all_words = str_word_count( $text, 2 );
  19.         $total_words = count( $all_words );
  20.        
  21.         // Determine the number of sentences
  22.         $total_sentences   = 0;
  23.         foreach( $periods as $punctuation )
  24.         {
  25.                 $total_sentences += substr_count( $text, $punctuation );
  26.         }
  27.  
  28.         // Get the number of long words, ie words longer than 6 characters
  29.         $long_words = 0;
  30.         foreach( $all_words as $word )
  31.         {
  32.                 if( strlen( $word ) > 6 )
  33.                 {
  34.                         $long_words++;
  35.                 }
  36.         }
  37.  
  38.         // Some basic math, http://sv.wikipedia.org/wiki/LIX
  39.         $average_sentence_length =  $total_words / $total_sentences;
  40.         $part_long_words = 100 * ( $long_words / $total_words );
  41.         $lix = $average_sentence_length + $part_long_words;
  42.  
  43.         return $lix;
  44. }
  45. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top