Simple formatting issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Simple formatting issue

Post by simonmlewis »

[text]41123531[/text]
How do I convert this result from a variable on-the-fly, into this:
[text]41,123,531[/text]
??

I don't know what you call the change to know how find it in php sites. I'm sure it's easy, but I don't have a clue. Thanks in advance.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Simple formatting issue

Post by social_experiment »

implode() can create that type of formatting but the original variable needs to been an array, the "glue" will then be used between each element.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Re: Simple formatting issue

Post by oscardog »

social_experiment wrote:implode() can create that type of formatting but the original variable needs to been an array, the "glue" will then be used between each element.
You're making hard work for yourself, there is already a function that does what he requires; number_format.
eivind
Forum Commoner
Posts: 28
Joined: Tue Apr 19, 2011 7:57 am

Re: Simple formatting issue

Post by eivind »

To really give it to you for free:

Code: Select all

echo number_format(41123531,0,".",",")
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Simple formatting issue

Post by simonmlewis »

luuuuvly. i knew there would be an inbuilt way.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply