Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-30-2007, 03:56 PM   PM User | #1
tbqfh
New Coder

 
Join Date: Jun 2007
Location: Northern England
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
tbqfh is an unknown quantity at this point
Question Maximum display of characters

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

PHP Code:
<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

Last edited by tbqfh; 07-30-2007 at 04:25 PM.. Reason: Changing the code container
tbqfh is offline   Reply With Quote
Old 07-30-2007, 04:09 PM   PM User | #2
daemonkin
Regular Coder

 
Join Date: Jun 2007
Location: N. Ireland
Posts: 351
Thanks: 16
Thanked 4 Times in 4 Posts
daemonkin is on a distinguished road
Substr

PHP Code:
$length 20;
echo 
substr($description,0,$length); 
D.
__________________
Daemonkin.
If this was helpful, please add to my reputation
Thousand Sons - Freelance Web Developer - ninetyonedegrees.com
daemonkin is offline   Reply With Quote
Old 07-30-2007, 04:12 PM   PM User | #3
tbqfh
New Coder

 
Join Date: Jun 2007
Location: Northern England
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
tbqfh is an unknown quantity at this point
Thanks but how does that go in my line? lol Sorry I'm pretty much a nube im reading up on it all though
tbqfh is offline   Reply With Quote
Old 07-30-2007, 05:26 PM   PM User | #4
Krokador
New Coder

 
Join Date: Mar 2007
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Krokador is on a distinguished road
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
Krokador is offline   Reply With Quote
Old 08-03-2007, 08:32 PM   PM User | #5
tbqfh
New Coder

 
Join Date: Jun 2007
Location: Northern England
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
tbqfh is an unknown quantity at this point
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?
tbqfh is offline   Reply With Quote
Old 08-05-2007, 10:50 PM   PM User | #6
tbqfh
New Coder

 
Join Date: Jun 2007
Location: Northern England
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
tbqfh is an unknown quantity at this point
Anyone? please
tbqfh is offline   Reply With Quote
Old 08-06-2007, 12:10 AM   PM User | #7
meth
Regular Coder

 
meth's Avatar
 
Join Date: Jan 2003
Posts: 262
Thanks: 0
Thanked 9 Times in 9 Posts
meth is on a distinguished road
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.
__________________
I do Web Design, Brisbane based.
More time spent in PHP/MySQL Web Development.
And Search Engine Optimisation takes up the rest of it.
meth is offline   Reply With Quote
Old 08-06-2007, 11:38 AM   PM User | #8
tbqfh
New Coder

 
Join Date: Jun 2007
Location: Northern England
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
tbqfh is an unknown quantity at this point
PHP Code:
<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

Thanks
tbqfh is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:50 AM.


Advertisement
Log in to turn off these ads.