wordpress - 想要修剪wordpress中的中文字母

标签 wordpress

我使用了wp_trim_words来获取Wordpress段落中的单词。该段落是中文字母。我想从 wordpress 段落中获取 10 个单词。但它正在展示更多的工作。我想。如果它实际是 10 个单词,那么我想取 30 个字符,所以我为此使用了 substr() 。这也返回一个不同的符号。

我用它来获得 10 个单词

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

显示是这样的

The picture after use wp_trim_wors 之后我也尝试过这个

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

我在使用 substr() 后得到了这个 this is after substr

最佳答案

您需要使用mb_substr而不是substr

mb_substr( get_the_content($postlist->post->ID), 0, 10, "utf-8" );

关于wordpress - 想要修剪wordpress中的中文字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51589250/

相关文章:

php - 如何将新项目文件夹连接到现有 MAMP 数据库?

mysql - 加速(重写?)不在子选择查询中

mysql - 替换wordpress WP_POSTS表中post_date字段的年份(4位数字)

wordpress - 使用 Bootstrap 的类别部分

php - require(public_html/mywebsite/wp-includes/post.php) 第 142 行的 :failed to open stream: permission denied in public_html/mywebsite/wp-settings. php

php - woocommerce 自定义结帐字段添加费用以订购 ajax

javascript - 如何通过 FTP 客户端将单独的 HTML 文件上传到 wordpress 站点?

WordPress插件: How-to add custom URL Handles

php - Wordpress 对两个表的自定义查询以获取分层数据

wordpress - 从 SSL 上的裸域重定向失败