ap_truncate_chars( string $text, int $limit = 40, string $ellipsis = '...' )
Description #
Truncate string but preserve full word.
Parameters #
- $textstring (Required) String.
- $limitint (Optional) Limit string to. Default value: 40
- $ellipsisstring (Optional) Ellipsis. Default value: '...'
Source #
File: includes/functions.php
function ap_truncate_chars( $text, $limit = 40, $ellipsis = '...' ) {
$text = wp_strip_all_tags( $text );
$text = str_replace( array( "\r\n", "\r", "\n", "\t" ), ' ', $text );
if ( strlen( $text ) > $limit ) {
$endpos = strpos( $text, ' ', (string) $limit );
if ( false !== $endpos ) {
$text = trim( substr( $text, 0, $endpos ) ) . $ellipsis;
}
}
return $text;
}
Expand full source code Collapse full source code View on GitHub: includes/functions.php:336
Add your comment