note 85326 deleted from function.mb-strimwidth by salathe

From: Date: Mon, 21 Sep 2020 14:57:13 +0000
Subject: note 85326 deleted from function.mb-strimwidth by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215385@lists.php.net to get a copy of this message
Note Submitter: CBieser ---- <?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; } ?>

« previous php.notes (#215385) next »