Jump to content

Shorter names.


cpugeek

Recommended Posts

I'm working on a website that hosts images in a gallery.but sometimes the names get too long and ruin the output of the page by pushing things over or folding the name over a couple of lines.what i was wondering is how would i shorten the names when displayed? like when the name were to reach a certain length the rest of the name would be replaced by 3 dots.here's an example of what i'm talking about.post-6055-1218141068_thumb.jpg

Link to comment
Share on other sites

You would have to use PHP, you'd do something like this:

// $str is the variable with the string in itif(strlen($str) > 25) {  $str = substr($str,0 25) . "...";}

Link to comment
Share on other sites

if ( strlen($name) >= 27) {				$name =  substr($name, 7, 22);  // strip off the http://			if ( strlen($name) >= 27) {	 // grab the next 15 characters				$front = substr($name, 0, 15);				}  			$back = substr($name, strlen($string)-5, 5); // grab the last 5 characters			$mid = "..."; // stuff the middle with an ellipse character			$name = $front . $mid . $back;  // glue the parts back			}

Here is a portion of a function I wrote for a script. Checks the length, grabs the first 15 characters, the last 5, and strings them together will an ellipse to show some parts are missing.(only if the length is over 20 characters) Adjust the numbers to suit your needs.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...