Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Rob Allen:
Using PHP's NumberFormatter to format currencies
Jul 29, 2013 @ 15:24:30

Rob Allen has a quick post showing how to use PHP's own NumberFormatter function to correctly format currencies (versus just number_format).

I've been using number_format() for a very long time, but recently discovered that within the intl extension there's a NumberFormatter class available too. This is quite a clever class as it is Locale aware and handles formatting currency, including the correct symbol. You can check if you have the intl extension installed using php -m | grep intl and if you don't then you can install it with apt-get install php5-intl or yum install php-intl assuming you use your distro's stock PHP. (If you compile your own, then --enable-intl is the switch you need.)

He gives some bits of example code showing you how to use this object, formatting the same amount for both the typical UK and German Euro formatting. The formater doesn't do any calculations for you, so the number you give it is what will come out the other side (no current exchange checks). He's also created a helper you can use if you're a Zend Framework v2 user.

tagged: numberformatter numberformat euro german uk

Link: http://akrabat.com/php/using-phps-numberformatter-to-format-currencies

Phil Thompson's Blog:
7 PHP functions that saved my life
Jan 22, 2008 @ 17:08:00

On his blog, Phil Thompson lists seven PHP functions that "saved his life" when developing his apps:

From time to time, I've struggled with minor pieces of coding for what seems like an age and then I've discovered PHP has a ready-made function whose express purpose seems to be to fix my exact problem. Today, I name and honour those PHP functions which saved my life, my career and my sanity.

Functions that made the cut include:

He has his own reasons for each - all of them being handy little functions that fill a specific niche in PHP's vast array of abilities.

tagged: handy function numberformat arrayvalues isset arraydiff

Link:

Phil Thompson's Blog:
7 PHP functions that saved my life
Jan 22, 2008 @ 14:12:50

On his blog, Phil Thompson lists seven PHP functions that "saved his life" when developing his apps:

From time to time, I've struggled with minor pieces of coding for what seems like an age and then I've discovered PHP has a ready-made function whose express purpose seems to be to fix my exact problem. Today, I name and honour those PHP functions which saved my life, my career and my sanity.

Functions that made the cut include:

He has his own reasons for each - all of them being handy little functions that fill a specific niche in PHP's vast array of abilities.

tagged: handy function numberformat arrayvalues isset arraydiff handy function numberformat arrayvalues isset arraydiff

Link:

Phil Thompson's Blog:
7 PHP functions that saved my life
Jan 22, 2008 @ 14:12:50

On his blog, Phil Thompson lists seven PHP functions that "saved his life" when developing his apps:

From time to time, I've struggled with minor pieces of coding for what seems like an age and then I've discovered PHP has a ready-made function whose express purpose seems to be to fix my exact problem. Today, I name and honour those PHP functions which saved my life, my career and my sanity.

Functions that made the cut include:

He has his own reasons for each - all of them being handy little functions that fill a specific niche in PHP's vast array of abilities.

tagged: handy function numberformat arrayvalues isset arraydiff handy function numberformat arrayvalues isset arraydiff

Link:


Trending Topics: