我使用wp_trim_words
来获取Wordpress段落中的单词。该段用中文写成。我想从wordpress段落中得到10个单词。但是它正在显示更多的工作。我认为。如果它实际为10个字,那么我想输入30个字符,因此我为此使用了substr()
。这也返回一个不同的符号。
我用它来获得10个单词
wp_trim_words( get_the_content($postlist->post->ID), 10 )
它是这样显示的
$ result = substr($ myStr,0,5);
答案 0 :(得分:1)
您需要使用mb_substr
而不是substr
。
mb_substr( get_the_content($postlist->post->ID), 0, 10, "utf-8" );
答案 1 :(得分:0)
最后,我得到了@George的回答,我从Google得到了这样的解释。我认为这会很有帮助
如果您使用从中进行子字符串化的多字节文本,它将影响脚本。如果是这种情况,我建议您在php.ini中启用mb_ *功能,或者执行ini_set(“ mbstring.func_overload”,2);