/ Published in: PHP

Shortens a string, and adds a span with a title of the full string.
Function is useful for listings where you don't want wraping; or for places where a long string liek a username can break the layout.
Function is useful for listings where you don't want wraping; or for places where a long string liek a username can break the layout.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Shorten a string **/ function format_shorten_string($string, $length = 15, $count_addition = 3) { if (drupal_strlen($string) > $length) { $out = theme('shorten_string', drupal_substr($string, 0, ($length - $count_addition)), $string, $count_addition); } else { $out = $string; } return $out; } /** * Function to theme the read more links * @ingroup themeable * @param $short_string The shortened string * @param $full_string The unshortened string, for display in the tooltip * @param $count_addition The amount of charanters that the calling function wants to be added. Defaults to three. Optional. */ function theme_shorten_string($short_string, $full_string, $count_addition = 3) { while ($i < $count_addition) { $i++; $addition .= '.'; } return '<span title="'. $full_string .'">'. $short_string . $addition .'</span>'; }
URL: http://webschuur.com
Comments
