ShoeLace1291 Posted April 28, 2008 Share Posted April 28, 2008 I have a database query that pulls a member's name out of the table. How would add "..." to the end of the name if the string is more than 7 characters? For example, the members would be John Smith, John Doe, Jane Doe. How would I make it appear like this: Jane Do... John Sm... John Do... Link to comment https://forums.phpfreaks.com/topic/103202-shorten-strings/ Share on other sites More sharing options...
dptr1988 Posted April 28, 2008 Share Posted April 28, 2008 I don't know how to do this in MySQL but here is how you could do it in PHP <?php $name = 'Jane Doe'; if (strlen($name) > 7) { $name = substr($name, 0, 7) . '...'; } ?> http://us3.php.net/substr http://us3.php.net/manual/en/function.strlen.php Link to comment https://forums.phpfreaks.com/topic/103202-shorten-strings/#findComment-528623 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.