3

I have used wp_trim_words for get words in Wordpress paragraph. The paragraph is in Chinese letter. I want to get 10 words from the wordpress paragraph. But it is showing more work. i think.If it actual 10 words, then i want to take 30 character, So i used substr() for this. This is also return a different symbol in this.

I have used this for getting 10 words

wp_trim_words( get_the_content($postlist->post->ID), 10 )

It is showing like this

The picture after use wp_trim_wors After this i have tried also this

$result = substr($myStr, 0, 5);

I got this after use substr() this is after substr

Ranjit
  • 1,684
  • 9
  • 29
  • 61

2 Answers2

1

You need to use mb_substr instead of substr.

mb_substr( get_the_content($postlist->post->ID), 0, 10, "utf-8" );
Vel
  • 9,027
  • 6
  • 34
  • 66
0

Finally, i got the answer by @George and i got the explanation like this from google. I think it will help a lot

It will impact your script if you work with multi-byte text that you substring from. If this is the case, I higly recommend enabling mb_* functions in your php.ini or do this ini_set("mbstring.func_overload", 2);

Please follow the link Difference between mb_substr and substr

Ranjit
  • 1,684
  • 9
  • 29
  • 61