Return to Snippet

Revision: 18366
at September 29, 2009 07:04 by svenito


Initial Code
public static function shortenNames($names) {
	$short_names = array();
	foreach ($names as $name) {
		if (strlen($name) > 15) {
			$front = substr($name, 0, 6);
			$back = substr($name, -6, 6);
			array_push($short_names, $front.'...'.$back);
		} else {
			array_push($short_names, $name);
		}
	}
	return $short_names;
}

Initial URL


Initial Description
Shortens all strings in an array to a maximum length. Inserts '...' in between the first and last 6 letters

Initial Title
Shorten strings in an array to a maximum length

Initial Tags
array

Initial Language
PHP