limiting links text to 20 characters only

Discussion in 'PHP' started by sp360, May 15, 2008.

  1. #1
    hi everyone,
    I have a problem converting my links text to only 20 characters. i need this code:
          $vidname = '<a href="'.$link.'single.php?id='.$id.'">'.$title.'</a>';
    	  echo $vidname;
    PHP:
    to automaically convert its links to only 20 characters. So if a a link is "abcdefghijklmnopqrstuvw" it will automatically be "abcdefghijklmnopqrst".

    I've tried
     if (strlen($vidname['title'])>20) { echo "...";}
    PHP:
    but still no hope. Please help:)
    Thanks, SP360
     
    sp360, May 15, 2008 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    
    
    if (strlen($vidname['title'])>20) { 
    
       $vidname['title'] = substr($vidname['title'],0,20).'...';
    }
    
    //However, I think you should be doing the editing to $title, not $vidname['title'], unless it is the value of $title.
    
    if (strlen($title)>20) { 
    
       $title = substr($title,0,20).'...';
    }
    $vidname = '<a href="'.$link.'single.php?id='.$id.'">'.$title.'</a>';
    echo $vidname;
    
    PHP:
    Peace,
     
    Barti1987, May 15, 2008 IP