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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Louisville, KY
    Posts
    279
    Thanks
    0
    Thanked 0 Times in 0 Posts

    add ... if longer than what is shown

    PHP Code:
    <?php echo substr($category_topic_list[$i]["title"],0,20); ?>
    If the title is longer than 20 characters, I'd like it to add "..." to the end to show that the title is longer than what is shown. Can this be done?

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    Code:
    <?php
    if (strlen($category_topic_list[$i]["title"]) > 20) {
      echo substr($category_topic_list[$i]["title"],0,20) . "...";
    } else {
      echo $category_topic_list[$i]["title"];
    }
    ?>

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Louisville, KY
    Posts
    279
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Makes perfect sense, don't know why I didn't think of that. Thank you so much!


  •  

    Posting Permissions

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