trim_characters() public static method

This function can be useful for excerpt of the post As opposed to wp_trim_words trims characters that makes text to take the same amount of space in each post for example
Since: 1.2.0
Author: @CROSP
public static trim_characters ( string $text, integer $num_chars = 60, string | null $more = null ) : string
$text string Text to trim.
$num_chars integer Number of characters. Default is 60.
$more string | null Optional. What to append if $text needs to be trimmed. Default '…'.
return string trimmed text.
コード例 #1
0
ファイル: test-timber-helper.php プロジェクト: timber/timber
 function testTrimCharacters()
 {
     $text = "Sometimes you need to do such weird things like remove all comments from your project.";
     $trimmed = \Timber\TextHelper::trim_characters($text, 20);
     $this->assertEquals("Sometimes yo…", $trimmed);
 }