Zblog article word count

informal essay two thousand one hundred and thirty-five 3 years ago (2020-02-27)

Place the following code in zb_ users/theme/ theme ID/template/post-single.php:

For example, the content of article $article Content is: Tuoyuan Network -www.toyean.com

Method 1:

 {php}echo mb_ strlen(preg_replace(array("'<(.*?)>'is","'&nbsp;'","'\n\r'","' '","'\r'","'\n'"),'',$article->Content),'UTF-8'){/php}

The above code will calculate both Chinese and English as one character, and the output result is: 18

Method 2:

 {php}echo mb_ strwidth(preg_replace(array("'<(.*?)>'is","'&nbsp;'","'\n\r'","' '","'\r'","'\n'"),'',$article->Content),'UTF-8'){/php}

The above code will calculate Chinese as 2 characters, English and punctuation as 1 character, and the output result is: 21


In common word count, we usually use the second method to count the number of words in an article.