-1

I am calling all names from a mysql database using php. Some names are very large. so i want to show first 7 charectors and put "..."

Here is my code:

<?php $result = mysql_query("SELECT * FROM Persons WHERE section='one' ORDER BY FirstName");
while($row = mysql_fetch_array($result))
{
    $fst = $row['FirstName']; ?>

Any suggestions please?

alon1234
  • 117
  • 1
  • 1
  • 6

2 Answers2

2

Try like

if(strlen($row['FirstName']) > 7)
     $fst = substr($row['FirstName'],0,7).'....'; 
GautamD31
  • 28,552
  • 10
  • 64
  • 85
1

try this:

if (strlen($fst) <7) {
    echo $fst;
    } 

else{
    echo substr($fst,0,7); echo "..."; 
    }
geovani075
  • 369
  • 1
  • 2
  • 12