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 9 of 9
  1. #1
    Regular Coder
    Join Date
    May 2003
    Location
    34 54' N 82 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding periods to the end

    http://www.net-riches.com/newnr/index.php?cat=arts

    What I am wanting to do on the side where the news is, I am wanting to make my script so that it will add before the end three periods like 'Spirit 'ready to rove' acro...' so the news item will only take up one line. I think it is 33 Characters across, including spaces.

    All help is welcome.

    Thanks.
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #2
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    PHP Code:

    $title 
    "Spirit ready to rove across the world";

    $title substr($title,0,30);

    $title $title."..."

  • #3
    Regular Coder
    Join Date
    May 2003
    Location
    34 54' N 82 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank You.
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    To make that more versatile in case you have variable length strings it would be

    PHP Code:

    $title 
    "Spirit ready to rove across the world";

    $title substr($title,0,strlen($title));

    $title .= "..."
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    Regular Coder
    Join Date
    May 2003
    Location
    34 54' N 82 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry to dig this up, but I need it again. Sorry

    Anyways, here is my problem. A line can hold 16 + or - characters. I want everything on that line that is over 16 characters to make as if it were 13 and add ... to the end. Spookster snippet is confusing to me.

    The code I am wanting to use this one is this.
    PHP Code:
        function topics()
        {    
            
    $this->connect();
            
    $result "SELECT id,author,topic,email,mood,date,entry FROM blog ORDER BY id DESC LIMIT 10";
            
    $sql mysql_query($result) or die(mysql_error());
            if(
    $sql){
                if(
    mysql_num_rows($sql) == "0"){
                    echo 
    "No information in the database!";
                }
            else{
                while(
    $row mysql_fetch_assoc($sql)){
                    
    $this->topic $row['topic'];
                    
    $this->id $row['id'];
                    echo 
    "<div><a href='des.php?mode=topic&id=$this->id'>$this->topic</a></div>\n";
                
                    }
                }
            }
        } 
    I want to make $this->topic the one with the ... on the end.

    Can anyone help?

    Once again, sorry to dig this up. Thanks
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    What's confusing about it? All I did was call the substring function which takes 3 parameters.

    substr([string to be processed],[index number of character to start at],[index number of character to stop at])

    so in mine I said

    substr($title,0,strlen($title));

    Take the substring of the string contained in the variable $title from index 0 to the index located at the end of the string which is retrieved by grabbing the length of the string.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Spookster, your snippet is confusing to me as well. If I understood Stevie correctly, he wants to truncate a string at a determined index, if it is longer than 16 characters. What your snippet does is to retrieve a substring from start to end of the string - essentially, it just makes a copy and appends the "...".

    Here's my take at it:

    PHP Code:
    if (strlen($row['topic']) > 16) {
        
    $this->topic substr($row['topic'], 013) . '...';
    } else {
        
    $this->topic $row['topic'];

    EDIT: Added "else" branch.
    Last edited by mordred; 02-29-2004 at 11:49 PM.
    De gustibus non est disputandum.

  • #8
    Regular Coder
    Join Date
    May 2003
    Location
    34 54' N 82 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Works great, mordred. Thanks
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #9
    Regular Coder dswimboy's Avatar
    Join Date
    Nov 2003
    Location
    mostly in Ann Arbor
    Posts
    458
    Thanks
    0
    Thanked 0 Times in 0 Posts
    don't forget that some letters are fatter than others with some fonts. it is hard to accomadate all combinations, but using a test letter like "D" or whatever letter looks fattest in the font your site prefers. then do the column text width based on that.


  •  

    Posting Permissions

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