When displaying the links on the page, use strlen() to get the size. If it is over a certain length, then echo the link, but for the part that's inbetweent he <a></a> tages, use substr() to get the first 40 characters of the string, put a ..., and then use substr to get the last few characters of the string.