From 52ba91be724c940bdfd60e055b1f40a688675dbc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 19 Sep 2007 23:15:01 +0000 Subject: [PATCH] Feature: La fonction trunc peut tronquer a droite ou a gauche --- htdocs/lib/functions.inc.php | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php index b9bef9f1fc3..cfebf548869 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.inc.php @@ -775,18 +775,37 @@ function dolibarr_print_phone($phone,$country="FR") \param size Longueur max de la chaine. Si 0, pas de limite. \return string Chaine tronquée */ -function dolibarr_trunc($string,$size=40) +function dolibarr_trunc($string,$size=40,$trunc='right') { if ($size==0) return $string; if ((!defined('USE_SHORT_TITLE')) || defined('USE_SHORT_TITLE') && USE_SHORT_TITLE) { - if (strlen($string) > $size) - return substr($string,0,$size).'...'; - else + // We go always here + if ($trunc == 'right') + { + if (strlen($string) > $size) + return substr($string,0,$size).'...'; + else + return $string; + } + if ($trunc == 'center') + { + // \TODO A developper. + return $string; + } + if ($trunc == 'left') + { + if (strlen($string) > $size) + return '...'.substr($string,strlen($string) - $size,$size); + else + return $string; + } } else + { return $string; + } } /**