Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jun 2007
    Location
    Northern England
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Regular Coder
    Join Date
    Jun 2007
    Location
    N. Ireland
    Posts
    351
    Thanks
    16
    Thanked 4 Times in 4 Posts
    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

  • #3
    New Coder
    Join Date
    Jun 2007
    Location
    Northern England
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks but how does that go in my line? lol Sorry I'm pretty much a nube im reading up on it all though

  • #4
    New Coder
    Join Date
    Mar 2007
    Posts
    76
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    New Coder
    Join Date
    Jun 2007
    Location
    Northern England
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #6
    New Coder
    Join Date
    Jun 2007
    Location
    Northern England
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone? please

  • #7
    Regular Coder meth's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Thanks
    0
    Thanked 9 Times in 9 Posts
    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.

  • #8
    New Coder
    Join Date
    Jun 2007
    Location
    Northern England
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •