Flesch-Kincaid Readability: Improve PHP function

前端 未结 4 1221
一生所求
一生所求 2021-02-09 04:39

I wrote this PHP code to implement the Flesch-Kincaid Readability Score as a function:

function readability($text) {
    $total_sentences = 1; // one full stop =         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-09 05:28

    I actually don't see any problems with that code. Of course, it could be optimized a bit if you really wanted to by replacing all the different functions with a single counting loop. However, I'd strongly argue that it isn't necessary and even outright wrong. Your current code is very readable and easy to understand, and any optimizations would probably make things worse from that perspective. Use it as it is, and don't try to optimize it unless it actually turns out to be a performance bottleneck.

提交回复
热议问题