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.
I think this happens because of line #364
* Creates an excerpt of a string
* It removes all html tags first and then uses str::short
*
* @param string $string The string to be shortened
* @param int $chars The final number of characters the string should have
* @param boolean $removehtml True: remove the HTML tags from the string first
* @param string $rep The element, which should be added if the string is too long. Ellipsis is the default.
* @return string The shortened string
*/
public static function excerpt($string, $chars = 140, $removehtml = true, $rep='…') {
if($removehtml) $string = strip_tags($string);
$string = str_replace(PHP_EOL, ' ', trim($string));
if(static::length($string) <= $chars) return $string;
return $chars == 0 ? $string : static::substr($string, 0, strrpos(static::substr($string, 0, $chars), ' ')) . $rep;
}
/**
* The widont function makes sure that there are no
* typographical widows at the end of a paragraph –
* that's a single word in the last line
*
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…
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
Any suggestion workaround for this one? thank You.
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:
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.
Oh yes thank You. It work like a charm. Really appreciate for Your help.
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.
1 Like