note 85326 modified in function.mb-strimwidth by mgf

From: Date: Wed, 27 Aug 2008 12:42:23 +0000
Subject: note 85326 modified in function.mb-strimwidth by mgf
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-143873@lists.php.net to get a copy of this message
<?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; } ?> --was-- // strimwidthCenter with little correction function strimwidthCenter( $value, $lenght = 40 ) { $valueEncoding = mb_detect_encoding( $value, 'auto', true ); if ( $lenght >= mb_strwidth( $value, $valueEncoding ) ) { return $value; } $limited = ''; $firstWidth = ceil( $lenght/2 ); $secondStart = mb_strwidth( $value, $valueEncoding ) - ( $lenght - $firstWidth ); $secondWidth = $lenght - $firstWidth +1; $limited = mb_strimwidth( $value, 0, $firstWidth, '...', $valueEncoding ) . mb_substr( $value, $secondStart, $secondWidth, $valueEncoding ); return $limited; } http://php.net/manual/en/function.mb-strimwidth.php

« previous php.notes (#143873) next »