# Kirby Excerpt Failed on Chinese Character

**URL:** <https://forum.getkirby.com/t/kirby-excerpt-failed-on-chinese-character/7358>\
**Category:** Questions\
**Tags:** v2\
**Created:** [April 28, 2017, 11:19pm UTC](https://forum.getkirby.com/t/kirby-excerpt-failed-on-chinese-character/7358 "2017-04-28T23:19:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![wallubee](https://avatars.discourse-cdn.com/v4/letter/w/22d042/32.png) [@wallubee](https://forum.getkirby.com/u/wallubee)\
**Post date:** [April 28, 2017, 11:19pm UTC](https://forum.getkirby.com/t/kirby-excerpt-failed-on-chinese-character/7358/1 "2017-04-28T23:19:47Z")

</div>

Hi, I have problem with chinese character. It seems it’s failed on character count.  
tried with:

`<?php echo str::excerpt( $post->text()->kirbytext(), 200, false); ?>`

and still no luck.

Here is the sample text:

弗洛雷斯有许多有趣的村庄.你不仅可以看到当地人如何生活以及邻里之间和访客之间如何互动，还可以看到当地文化是如何保护和保存下来的.你也可以从他们那里学习到如何与自然保持平衡. 一旦你充分了解塔多村(Tado Village)，那么你会看到这一切.

塔多村位于拉布汉巴焦港口以东约45公里.如果你想看看当地芒格莱伊人(Manggaraians)如何生活和坚持他们的文化传统，这里便是最合适的地方.你会看到他们很自豪地穿着他们的传统服装.当他们以传统的欢迎仪式公开接待你时，你也会被当地人的热情和好客而感动.

沿着从拉布汉巴焦到塔多村的公路，自然的“珍品”全展现在人们眼前：古老的村落，美丽的山丘，还有茂密的雨林.另一个不容错过的景象是如蜘蛛网般的稻田.当地方言称之为“lingko”.在过去，这些独特的引人注目的稻田结构，是用来划分村里不同家庭的土地所有权的.

塔多村拥有非常丰富的文化.村民在社区里实行生态旅游，经常举办各种文化活动和聚会，包括吟唱祖传歌曲，讲述民间传说或当地故事，以及跳舞.这可能是村民保存本村文化的方式.每一代人都有义务学习所有的歌曲，故事和舞蹈，并传承给下一代.这就不难怪，即使没有现代的技术，这些文化依然可以保存下来.村民拥 有娱乐和创新的源泉，并为他们的文化遗产感到骄傲.然而他们也十分谦虚，欢迎来自各地的游客.

Any help would be appreciated. Thank You.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [April 29, 2017, 7:10am UTC](https://forum.getkirby.com/t/kirby-excerpt-failed-on-chinese-character/7358/2 "2017-04-29T07:10:39Z")

</div>

I think this happens because of line #364

> <https://github.com/getkirby/kirby/blob/master/vendor/getkirby/toolkit/lib/str.php#L364>

The function looks for the next space after the shortened substring. Seems that the next space after the 200 chars seems to be a bit away…

---

<div class="post-metadata">

**Author:** ![wallubee](https://avatars.discourse-cdn.com/v4/letter/w/22d042/32.png) [@wallubee](https://forum.getkirby.com/u/wallubee)\
**Post date:** [April 29, 2017, 12:32pm UTC](https://forum.getkirby.com/t/kirby-excerpt-failed-on-chinese-character/7358/3 "2017-04-29T12:32:52Z")

</div>

No it’s not about character length. Put any value and result will be the same.  
\<?php echo excerpt( $post-\>text()-\>kirbytext(), 200); ?\>  
is not work too.

Well someone have the problem before and seems it’s not resolved yet.  
[https://github.com/getkirby/kirby/issues/259](https://github.com/getkirby/kirby/issues/259)

Any suggestion workaround for this one? thank You.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [April 29, 2017, 12:47pm UTC](https://forum.getkirby.com/t/kirby-excerpt-failed-on-chinese-character/7358/4 "2017-04-29T12:47:46Z")

</div>

I didn’t say it was about character length. For me the result is different if I test with 100, 200 or 400 chars. But what I said was that the function looks for the next space AFTER 100, 200 or whatever number of characters.

If you replace line 364 with this:

```auto
return $chars == 0 ? $string : static::substr($string, 0, $chars) . $rep;

```

the result should be what you are looking for. Correct me if I’m wrong.

But this requires mb\_string to be enabled, of course.

---

<div class="post-metadata">

**Author:** ![wallubee](https://avatars.discourse-cdn.com/v4/letter/w/22d042/32.png) [@wallubee](https://forum.getkirby.com/u/wallubee)\
**Post date:** [April 29, 2017, 1:04pm UTC](https://forum.getkirby.com/t/kirby-excerpt-failed-on-chinese-character/7358/5 "2017-04-29T13:04:38Z")

</div>

Oh yes thank You. It work like a charm. Really appreciate for Your help.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [April 29, 2017, 1:17pm UTC](https://forum.getkirby.com/t/kirby-excerpt-failed-on-chinese-character/7358/6 "2017-04-29T13:17:56Z")

</div>

Please keep in mind that this change will then cut words in other languages right in the middle, so you may want to create a custom function you only use for Chinese or similar languages.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:50pm UTC](https://forum.getkirby.com/t/kirby-excerpt-failed-on-chinese-character/7358/7 "2025-02-06T16:50:06Z")

</div>

Archived on February 6, 2025, 4:50pm UTC


