Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Hey, I have made a little code library to link to code snippets I uplaod to my website. In my mysql table I have a column called code_desc

    On the main page, where I link to the code's, I display the name of the file, the language, and the link, however, I want to display some of the code_desc field.

    For instance, if the field is 70 characters, show 50, and then have a link saying "Full description here" which acts in the same way as the link (takes you to the code snippet)

    Is this possible?

    A similar system is in place on planetsourcecode, although they show the test "description truncated" I think.

    Thanks in advance

  2.  

  3. #2
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    Well that is easy enough to accomplish with php's substr function.

    PHP Code:
    $description;  // assume this contains your description
    $display;      // will contain the end result.
    if( strlen($description) > 50 )
    {
        
    $display substr($description050);
        
    $display .= "...";
    }
    else
    {
        
    $display $description;
    }

    print(
    $display); 
    There and Back Again :Ogre:

  4. #3
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    That works great, but just 1 addition?

    Right now it will cut off right in the middle of a word, is there a way so that once it is passed or at the substr upper limit (in this case 50) it cuts off after a " " (a space)?

    Thanks again though!

  5. #4
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    There is always a way. I'll try to come up with something and post it later today.
    There and Back Again :Ogre:


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:03 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com