function getTrunc($n, $l) { if (!isset($n{$l}) { return $n; } $n = explode(' ', substr($n, 0, $l)); if (count($n)>1) { unset($n[count($n)-1]); } return implode(' ', $n).'...'; }
your checking the size before its exploded, getTrunc(12345,2) will return 12345 instead of 12