Jump to content

String Formatting


Gex

Recommended Posts

String FormattingHey, I just have been wondering. Having unsuccessfully (Or probably not looking hard enough) to find a way to format a string of words. What I wish to do is on my website I have the current users online. All the users online are in a list something like this. Player, Player, Player, Player,Now the problem I having, well not a problem really more of a cosmetic appearance to the overall look, what is happening is that when it outputs the data the last user online in the list has player, a comma at the end. Being the last in the list of online players I do not what a comma there. Is there a way to format the output so PHP knows when it has reach the end of a list. Thanks in advance.Gex

Link to comment
Share on other sites

You could put them all in a list, then implode() said list. Or you could count along (using a variable) as you iterate through the names, and do something different when you come to the last one.

Link to comment
Share on other sites

If they're in a simple list you could just do a trim() on the data and clip off the last comma before you display them:$data = trim($data, ',');

Now the problem I having, well not a problem really more of a cosmetic appearance to the overall look, what is happening is that when it outputs the data the last user online in the list has player, a comma at the end. Being the last in the list of online players I do not what a comma there. Is there a way to format the output so PHP knows when it has reach the end of a list.
Link to comment
Share on other sites

Thanks guys, i'll give them a shot and see what comes out.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...