Flesch-Kincaid-Lesbarkeit: Verbessern Sie die PHP-Funktion

Ich habe diesen PHP-Code geschrieben, um den Flesch-Kincaid Readability Score als Funktion zu implementieren:

function readability($text) {
    $total_sentences = 1; // one full stop = two sentences => start with 1
    $punctuation_marks = array('.', '?', '!', ':');
    foreach ($punctuation_marks as $punctuation_mark) {
        $total_sentences += substr_count($text, $punctuation_mark);
    }
    $total_words = str_word_count($text);
    $total_syllable = 3; // assuming this value since I don't know how to count them
    $score = 206.835-(1.015*$total_words/$total_sentences)-(84.6*$total_syllables/$total_words);
    return $score;
}

Haben Sie Vorschläge zur Verbesserung des Codes? Ist es richtig? Wird es funktionieren?

Ich hoffe ihr könnt mir helfen. Danke im Voraus!

Antworten auf die Frage(4)

Ihre Antwort auf die Frage