<?php
function strimwidthCenter( $value, $length = 40 ) {
$valueEncoding = mb_detect_encoding( $value, 'auto', true );
if ( $length >= mb_strwidth( $value, $valueEncoding ) ) {
return $value;
}
$limited = '';
$firstWidth = ceil( $length/2 );
$secondStart = mb_strwidth( $value, $valueEncoding ) - ( $length - $firstWidth );
$secondWidth = $length - $firstWidth +1;
$limited = mb_strimwidth( $value, 0, $firstWidth, '...', $valueEncoding ) . mb_substr( $value, $secondStart, $secondWidth, $valueEncoding );
return $limited;
}
?>