Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi there,

    you will need some kind of regex to count them correctly.
    See here, where a user had a similar issue with Greek characters:

    https://generatepress.com/forums/topic/reading-time-php-little-help-if-possible/page/2/#post-2079125

    The important part is where the wordcount is done:

    $word_count = count(preg_split('/\P{L}/usi', $clean_content, -1, , PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY));

    Try changing that line to:

    $word_count = count(preg_split('/\p{Han}+/u', $clean_content, -1, , PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY));

    Thread Starter kslim

    (@kslim)

    Hi David,

    Thank you so much, all the reading time makes sense now. By the way I made a modification by removing the extra “,” from the code:

    $word_count = count(preg_split('/\p{Han}+/u', $clean_content, -1, REG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY));

    Thank you again!

    Awesome – glad to hear you got that to work!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Estimated Reading Time for Chinese Characters’ is closed to new replies.