TheFilmGod Posted September 15, 2007 Share Posted September 15, 2007 Hello, I have a string. Sometimes it's too small, sometimes too big. I want php to cut it down to a max of 30 characters and then add "..." at the end of the it. How do i do this? Quote Link to comment https://forums.phpfreaks.com/topic/69498-solved-php-cut-it-down/ Share on other sites More sharing options...
rarebit Posted September 15, 2007 Share Posted September 15, 2007 $len = strlen($s); if ($len > 30) { $s = substr($s, 0, 30); } elseif ($len < 30) { $s = str_pad($s, 30 , "."); } or something like that... Quote Link to comment https://forums.phpfreaks.com/topic/69498-solved-php-cut-it-down/#findComment-349202 Share on other sites More sharing options...
TheFilmGod Posted September 15, 2007 Author Share Posted September 15, 2007 // Calculate length of $name and cut it down if needed $len_name = strlen($name); if ($len_name > 12) { $name = substr($name, 0, 12); $name = "$name" . "..."; } Is what I was looking for. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/69498-solved-php-cut-it-down/#findComment-349210 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.