Automattic\WooCommerce\Blocks\BlockTypes

ProductSummary::count_textprivateWC 1.0

Count words, characters (excluding spaces), or characters (including spaces).

Method of the class: ProductSummary{}

No Hooks.

Returns

Int. Count of specified type.

Usage

// private - for code of main (parent) class only
$result = $this->count_text( $text, $count_type );
$text(string) (required)
Text to count.
$count_type(string) (required)
Count type: 'words', 'characters_excluding_spaces', or 'characters_including_spaces'.

ProductSummary::count_text() code WC 9.8.5

private function count_text( $text, $count_type ) {
	switch ( $count_type ) {
		case 'characters_excluding_spaces':
			return strlen( preg_replace( '/\s+/', '', $text ) );
		case 'characters_including_spaces':
			return strlen( $text );
		case 'words':
		default:
			return str_word_count( wp_strip_all_tags( $text ) );
	}
}