PDA

View Full Version : Trimming Row output for display


Jolten
09-10-2004, 01:08 AM
Hi,

I've got a query and string to display some information and usernames. One problem I'm having is long usernames. I'd like to truncate usernames longer than 8 characters to 6 characters then add ... after it. I can't seem to get this working in my while loop. Any help would be appreciated.

here's what I've got right now inside the while loop

if (strlen($row2->strUsrid) > 8)
{
$Winner = substr($row2->strusrid, 0, 8 - 2) . '..';
}

Colin F
09-10-2004, 03:59 AM
why are you doing 8-2 and not just 6?

Jolten
09-10-2004, 04:14 AM
well 6 wasn't working.

Modin
09-14-2004, 02:22 AM
is Usrid the variable you want to be trimming? It would seem intuitive to be trimming a variable called Username (or whatever you store it in).

Unless of course you have the username stored in that variable.

Brad
09-14-2004, 03:01 AM
Use this:

// is $username longer then 8 char?
if (strlen($username) > 8)
{
// long username, strip it down to 6 char
$username = substr($username, 0, 6);
// append '....' to the end of the username
$username .= '....';
}

Jolten
09-14-2004, 04:03 AM
Thanks Brad.loo. That worked perfectly with the substituted string I needed to trim.

(and yes it was strusrid it's a custom table not native to vb3.)