Feature: La fonction trunc peut tronquer a droite ou a gauche

This commit is contained in:
Laurent Destailleur
2007-09-19 23:15:01 +00:00
parent 897e42668b
commit 52ba91be72

View File

@@ -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<71>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;
}
}
/**