Automattic\WooCommerce\Blocks\BlockTypes
ProductSummary::trim_characters
Trim characters to a specified length.
Метод класса: ProductSummary{}
Хуков нет.
Возвращает
Строку. Trimmed text.
Использование
// private - только в коде основоного (родительского) класса $result = $this->trim_characters( $text, $max_length, $count_type );
- $text(строка) (обязательный)
- Text to trim.
- $max_length(int) (обязательный)
- Maximum length of the text.
- $count_type(строка) (обязательный)
- What is being counted. One of
'words','characters_excluding_spaces', or'characters_including_spaces'.
Код ProductSummary::trim_characters() ProductSummary::trim characters WC 10.8.1
private function trim_characters( $text, $max_length, $count_type ) {
$pure_text = wp_strip_all_tags( $text );
$trimmed = mb_substr( $pure_text, 0, $max_length );
if ( 'characters_including_spaces' === $count_type ) {
return $trimmed;
}
preg_match_all( '/([\s]+)/', $trimmed, $spaces );
$space_count = ! empty( $spaces[0] ) ? count( $spaces[0] ) : 0;
return mb_substr( $pure_text, 0, $max_length + $space_count );
}