Gives the Spache readability score of text entered rounded to one digit
@param   boolean|string  $strText         Text to be checked
@return  int|float
772095
public function spacheReadabilityScore($strText = false)
    {
        $strText = $this->setText($strText);

        $score = Maths::bcCalc(
            Maths::bcCalc(
                Maths::bcCalc(
                    0.121,
                    '*',
                    Maths::bcCalc(
                        Text::wordCount($strText, $this->strEncoding),
                        '/',
                        Text::sentenceCount($strText, $this->strEncoding)
                    )
                ),
                '+',
                Maths::bcCalc(
                    0.082,
                    '*',
                    $this->spacheDifficultWordCount($strText)
                )
            ),
            '+',
            0.659
        );

        if ($this->normalise) {
            return Maths::normaliseScore($score, 0, 5, $this->dps); // Not really suitable for measuring readability above grade 4
        } else {
            return Maths::bcCalc($score, '+', 0, true, $this->dps);
        }
    }
74720
public static function prepare_attr_value ($text) {
		if (is_array($text)) {
			/** @noinspection ForeachSourceInspection */
			foreach ($text as &$t) {
				$t = static::prepare_attr_value($t);
			}
			return $text;
		}
		return strtr(
			$text,
			[
				'&'  => '&amp;',
				'"'  => '&quot;',
				'\'' => '&apos;',
				'<'  => '&lt;',
				'>'  => '&gt;'
			]
		);
	}
604619
protected function parseAttr($text)
    {
        $atts = [];

        $pattern = '/(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';

        $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text);

        if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) )
        {
            foreach ($match as $m)
            {
                if (!empty($m[1]))
                    $atts[strtolower($m[1])] = stripcslashes($m[2]);
                elseif (!empty($m[3]))
                    $atts[strtolower($m[3])] = stripcslashes($m[4]);
                elseif (!empty($m[5]))
                    $atts[strtolower($m[5])] = stripcslashes($m[6]);
                elseif (isset($m[7]) and strlen($m[7]))
                    $atts[] = stripcslashes($m[7]);
                elseif (isset($m[8]))
                    $atts[] = stripcslashes($m[8]);
            }
        }
        else
        {
            $atts = ltrim($text);
        }

        return $atts;
    }
1088560
public function smogIndex($strText = false)
    {
        $strText = $this->setText($strText);

        $score = Maths::bcCalc(
            1.043,
            '*',
            Maths::bcCalc(
                Maths::bcCalc(
                    Maths::bcCalc(
                        Syllables::wordsWithThreeSyllables($strText, true, $this->strEncoding),
                        '*',
                        Maths::bcCalc(
                            30,
                            '/',
                            Text::sentenceCount($strText, $this->strEncoding)
                        )
                    ),
                    'sqrt',
                    0
                ),
                '+',
                3.1291
            )
        );

        if ($this->normalise) {
            return Maths::normaliseScore($score, 0, $this->maxGradeLevel, $this->dps);
        } else {
            return Maths::bcCalc($score, '+', 0, true, $this->dps);
        }
    }
80133
public static double daleChallScore(String strText) {
        strText = cleanText(strText);
        int intDifficultWordCount = 0;
        List<String> arrWords = (new WhitespaceTokenizer()).tokenize(strText);
        int intWordCount = arrWords.size();
        for (int i = 0; i < intWordCount; ++i) {
            if (!DALECHALL_WORDLIST.contains(arrWords.get(i))) {
                ++intDifficultWordCount;
            }
        }
        int intSentenceCount=sentenceCount(strText);

        double percentageOfDifficultWords=intDifficultWordCount/(double)intWordCount;
        double score=0.1579*(100*percentageOfDifficultWords)+0.0496*(intWordCount/(double)intSentenceCount);
        if(percentageOfDifficultWords>0.05) {
            score+=3.6365;
        }

        return score;
    }
1221978
private static int determineConsecutiveTextCount(CharSequence msg, int startpos) {
    int len = msg.length();
    int idx = startpos;
    while (idx < len) {
      char ch = msg.charAt(idx);
      int numericCount = 0;
      while (numericCount < 13 && isDigit(ch) && idx < len) {
        numericCount++;
        idx++;
        if (idx < len) {
          ch = msg.charAt(idx);
        }
      }
      if (numericCount >= 13) {
        return idx - startpos - numericCount;
      }
      if (numericCount > 0) {
        //Heuristic: All text-encodable chars or digits are binary encodable
        continue;
      }
      ch = msg.charAt(idx);

      //Check if character is encodable
      if (!isText(ch)) {
        break;
      }
      idx++;
    }
    return idx - startpos;
  }
739538
public static function averageWordsPerSentence($strText, $strEncoding = '')
    {
        $intSentenceCount = self::sentenceCount($strText, $strEncoding);
        $intWordCount = self::wordCount($strText, $strEncoding);

        $averageWords = (Maths::bcCalc($intWordCount, '/', $intSentenceCount));
        return $averageWords;
    }
210059
public static function withCheckDigitForIsbn10($isbn)
    {
        // Sanitize
        $isbn = preg_replace('/[^0-9]/', '', $isbn);
        $isbn = substr($isbn, 0, 9);

        // Validate
        if (strlen($isbn) != 9) {
            return null;
        }

        // Calculate (sum)
        $sum = 0;
        for ($i = 0; $i < 9; $i++) {
            $sum += (10 - $i) * $isbn{$i};
        }

        // Calculate (check digit)
        $checkDigit = 11 - ($sum % 11);
        $checkDigit = $checkDigit == 10 ? "X" : ($checkDigit == 11 ? 0 : $checkDigit);

        return $isbn . $checkDigit;
    }
1287327
protected function col_random_guess_score($questionstat) {
        if ($this->is_calculated_question_summary($questionstat)) {
            list($min, $max) = $questionstat->get_min_max_of('randomguessscore');
            return $this->format_percentage_range($min, $max);
        } else if (is_null($questionstat->randomguessscore)) {
            return '';
        } else {
            return $this->format_percentage($questionstat->randomguessscore);
        }
    }
1094824
public static function ctype_alnum($text)
    {
        $text = self::convert_int_to_char_for_ctype($text);

        return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text);
    }
1101365
private static double averageWordsPerSentence(String strText) {
        int intSentenceCount = sentenceCount(strText);
        int intWordCount = wordCount(strText);
        return (intWordCount / (double)intSentenceCount);
    }
215624
private static double percentageWordsWithThreeSyllables(String strText) {
        int intWordCount = wordCount(strText);
        int intLongWordCount = wordsWithThreeSyllables(strText);
        double percentage = ((intLongWordCount / (double)intWordCount) * 100.0);
        return percentage;
    }
276128
public function readTab($text) {
		$pieces = explode("\n", $text);
		$result = [];
		foreach ($pieces as $piece) {
			$tmp = explode("\t", trim($piece, "\r\n"));
			$result[] = $tmp;
		}
		return $result;
	}
654079
public static function ctype_lower($text)
    {
        $text = self::convert_int_to_char_for_ctype($text);

        return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text);
    }
1102268
public function letterCount($strText = false)
    {
        $strText = $this->setText($strText);

        return Text::letterCount($strText, $this->strEncoding);
    }
315040
private function getScorePercent($each_score)
    {
        $temp_vote = $each_score->find('td', 1)->find('span small', 0)->plaintext;
        $percent = $each_score->find('td', 1)->find('span', 0)->plaintext;
        $percent = str_replace([$temp_vote, '%', "\xc2\xa0"], '', $percent);

        return trim($percent);
    }
281473
public static function textLength($strText, $strEncoding = '')
    {

        if (is_null(self::$blnMbstring)) {
            self::$blnMbstring = extension_loaded('mbstring');
        }

        if (!self::$blnMbstring) {
            $intTextLength = strlen($strText);
        } else {
            if ($strEncoding == '') {
                $intTextLength = mb_strlen($strText);
            } else {
                $intTextLength = mb_strlen($strText, $strEncoding);
            }
        }

        return $intTextLength;
    }