Click to See Complete Forum and Search --> : Truncate string problem


LocalHero
11-28-2005, 11:05 PM
I have this code that works...kinda.
echo(substr($transaction, 0, 45) . "...");
When I have a long string it shortens it and has ... to tell me that there is more. But short strings also have ... and may be confusing on strings close to the cutoff number (45). Is there a better way of doing this?

chazzy
11-28-2005, 11:19 PM
$substr ="";
if(strlen($transaction)>45){
$substr=substr($transaction,0,45)."...";
}
else{
$substr = $transaction;
}
echo $substr;


that should work.

LocalHero
11-28-2005, 11:34 PM
I did, Thanks!