Jump to content

Shorter names.


cpugeek
 Share

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...