How to trim script output?

Discussion in 'Programming' started by lokielookies, Feb 11, 2009.

  1. #1
    I want to limit the number of characters in a script output.

    To see what I mean, go here.

    The 4th title on the page needs to be trimmed, but I can't seem to find out how to do it.

    A little help would be appreciated
     
    lokielookies, Feb 11, 2009 IP
  2. fdoze

    fdoze Peon

    Messages:
    205
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    In PHP just use Trim function.
     
    fdoze, Feb 11, 2009 IP
  3. tihan

    tihan Active Member

    Messages:
    64
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #3
    $max_chars = 40;
    if (strlen($title) > $max_chars) {$tok = strtok($title," ");$kim = $tok;
    if (strlen($kim) < ($max_chars-10)) {$tok = strtok(" ");$kim = $kim." ".$tok;};
    if ($kim != "$title") {$kim.="...";};
    $title = $kim;
     
    tihan, Feb 11, 2009 IP
  4. buldozerceto

    buldozerceto Active Member

    Messages:
    1,137
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    88
    #4
    use functions like substr and or wordwrap.
     
    buldozerceto, Feb 11, 2009 IP