trimtext with display

Text too long…? Not wrapping, or pushing other elements around…? I wrote this little function to trim text to any length, adding ‘…’ at the end if trimmed. Then, it displays the full text as you hover over it. Cooool!

  $text2 = substr($text,0,($max - 3));
  $text2 .= "...";
  return $text2;

$text = '123456789';
echo trimtext($text,6);

Displays: 123.. (Hover over for full text)

Leave a Reply