One little tweek to make it a little faster is to use isset() instead of strlen(). This is because isset() is a language construct and not a function.
if ($l >= strlen($n)) return $n; to: if (!isset($n{$l})) return $n;
note using $string{$length} counts from zero.