Dysan Posted November 30, 2007 Share Posted November 30, 2007 Hi, I am currently displaying people's names on the screen, but some people's names are longer than others. How do I display only 6 characters of a person's name, then display three dots (...) at the end. $result = mysql_query("SELECT * FROM person"); while($row = mysql_fetch_array($result)) { echo $row['name']; } Quote Link to comment Share on other sites More sharing options...
MadTechie Posted November 30, 2007 Share Posted November 30, 2007 try this <?php echo (strlen($row['name'])>6)?substr($row['name'], 0, 6)."...":$row['name']; ?> OR a function (if used many times) <?php echo shortname($row['name'], 6); function shortname($name, $len) { return (strlen($name)>$len)?substr($name, 0, $len)."...":$name; } ?> 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.