Zblog article word count

informal essay five thousand four hundred and ninety-four 4 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.