Zen Cart Limit Description Length

Discussion in 'PHP' started by scottlpool2003, May 4, 2011.

  1. #1
    Hi guys, having a small problem with Zen Cart.

    I have a module which displays the description of the product.

    The problem is, that the general description looks messy. The easiest way to explain is to show you:

    madabouttoys.co.uk/index.php?main_page=product_info&cPath=1&products_id=3

    The description on the right of the image needs to be limited to around 200 characters so that the full description is listed below under the "Description" tag.

    Here is the code containing the description:

    <div id="mainproductright">
    <?php if ($products_description != '') { ?>
    <div id="productDescription" class="productGeneral biggerText"><?php echo stripslashes($products_description); ?></div>
    <?php } ?>
    
    <p class="dividerline">&nbsp;</p>
    <p><strong>Our Price:</strong></p>
    PHP:
    If somebody can limit the length of the description, that would be fantastic!

    Thanks in advance.
     
    scottlpool2003, May 4, 2011 IP
  2. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #2
    Thanks for your help everyone, it's appreciated.

    I solved it myself by looking for a PHP code to limit the length of a string and added:


    <?php $limit = 500; $summary = $products_description; if (strlen($summary) > $limit)
    $summary = substr($summary, 0, strrpos(substr($summary, 0, $limit), ' ')) . '...';?> <?php echo stripslashes($summary); ?>

    Thanks again.
     
    scottlpool2003, May 4, 2011 IP