View Full Version : Maximum display of characters

07-30-2007, 04:56 PM
Hi Guys

I have got this problem on my site where I have a new products module and the name length varies quite allot and if it goes on to two lines it makes the images all go out of line and ugly so what I wanted to know is there a way I can make it only display part of the name up to a certain amount of characters like this.

"new product for... " instead of "new product for sale bla bla bla"

This is the code that displays the name of the product at the moment

<a title="more info" href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . 'more-info-sml.gif','',60,14) . '</a>

Thanks in advance

07-30-2007, 05:09 PM
Substr (http://uk3.php.net/manual/en/function.substr.php)

$length = 20;
echo substr($description,0,$length);


07-30-2007, 05:12 PM
Thanks but how does that go in my line? lol Sorry I'm pretty much a nube im reading up on it all though

07-30-2007, 06:26 PM
well basically you would use the function on your product name.

Your code seems to only show an image-link, anyway the part you provided. But let's say you have $product_name in front of the link, you'd change $product_name for substr($product_name, 0, $length)

which will take the characters from the start of the string(0) and take $lenght characters.

hope that helps

08-03-2007, 09:32 PM
Thanks for that I think im really close now lol

When i put it in now it replaces the product name with 'array'

any ideas?

08-05-2007, 11:50 PM
Anyone? please

08-06-2007, 01:10 AM
The snippet that you've posted is not the code that generates the anchor text of the img link. Trawl through your scripts and find a function called tep_image(). Post that code and we'll be able to help further.

08-06-2007, 12:38 PM
<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . '</a><br>

Sorry this is the bit of code in question.

I have tried putting the length in to it and as i said it puts 'array' where the product name should be