May 24, 2007

Truncate a string without breaking a word

function truncate_str($string, $length = 80, $etc = '...',$break_words = false)
{
if ($length == 0)
return '';
if (strlen($string) > $length) {
$length -= strlen($etc);
if (!$break_words)
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1));
return substr($string, 0, $length).$etc;
} else
return $string;
}

1 comment:

Anonymous said...

Alternatives to CNC machining could take a lot longer} to execute or have larger probabilities of errors. Changing your requested attributes can scale back your CNC machining project’s value. Some issues in a position to} do} tomake your CNC machining project more budget-friendlyinclude preserving the project simple, decreasing the necessity for extra-thin partitions on parts and growing tolerances. CNC machines’ capability to store designs eliminates the need to|the necessity to} keep further copies. For example, you'll be able to|you probably can} unlock some area while not having extra information, flash drives or other pc information of outdated designs. Baby Bottle Warmers While you’ll likely still wish to keep a backup copy of prototype designs, storage for exhausting copies can be a a|could be a} thing of the previous.