Zepo. Posted December 2, 2007 Share Posted December 2, 2007 How do i take a variable say $name and trim it down to ohh, say 8 characters. Then have a ... after the name if it's trimmed. Quote Link to comment Share on other sites More sharing options...
trq Posted December 2, 2007 Share Posted December 2, 2007 substr. Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted December 2, 2007 Share Posted December 2, 2007 $name = "some long string hey"; $max_length = 8; // 8 chars max if (strlen($name) > $max_length) { substr($name,0,$max_length-1); // make it 8 chars long $name .= "..."; // add an ellipses ... at the end } else {} Quote Link to comment Share on other sites More sharing options...
Zepo. Posted December 2, 2007 Author Share Posted December 2, 2007 Hmmm didnt trim it, but it did add and elipsis to the end... Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted December 2, 2007 Share Posted December 2, 2007 <?php $name = "Blah blah blah blah"; if (strlen($name) > $name = substr($name,0,.'...'; echo $name; ?> Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted December 2, 2007 Share Posted December 2, 2007 ^ thats the exact same thing i did.. only yours is less explanitory edit.. i had a booboo in my code use this $name = "some long string hey"; $max_length = 8; // 8 chars max if (strlen($name) > $max_length) { $name = substr($name,0,$max_length-1); // i didnt have the $name = on this line the first time lol $name .= "..."; // add an ellipses ... at the end } else {} Quote Link to comment Share on other sites More sharing options...
Zepo. Posted December 2, 2007 Author Share Posted December 2, 2007 Works, thanks. =] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.