Chris Schuld's Blog

personal musings on the composition of software

Format.php – v1.0
download
format-v1-0.zip – v1.0
release: 2/24/2009
md5: 8de8157e010d81159e650441d480033c
View typical usage examples

Format.php is a class used statically to formation information to and from the user. Right now the class is fairly US based because that is where most of my applications are from. If you would like to help update some of the functions to have better international support please let me know.

Here are some of the functions that Format.php provides:

Phone Number Formatting: (ZZZ) ZZZ-ZZZZ x YYY
Phone Number Formatting for Storage: numbers only
Please Note: In all of my applications I usually do not store the phone numbers as the users enter them but rather format them into something the application can use and understand (I pack them and un-pack them with known heuristics).

USD: USA dollar format: $0000.00
Bytes: format a number given as bytes into a readable format such as 32MB
KiloBytes: format a number give as kilobytes into a readable format such as 23GB

Here is some typical usage:

echo Format::phoneNumberForStorage('480-373-6581').'<br/>';
echo Format::phoneNumberForStorage('373-6581').'<br/>';
echo Format::phoneNumber(Format::phoneNumberForStorage('800-959-0045')).'<br/>';
echo Format::phoneNumber('3736581').'<br/>';
echo Format::phoneNumber('3736581','480').'<br/>';
echo Format::usd(56.32).'<br/>';
echo Format::bytes(20375237).'<br/>';
echo Format::kilobytes(20375237).'<br/>';

This typical usage will output this:

4803736581
3736581
(800) 959-0045
373-6581
(480) 373-6581
$56.32
19.43 MB
19.43 GB

3 Responses to " Format.php – Formatting User I/O "

  1. Aladin says:

    Thank you.

  2. Nilesh says:

    thank you, will certainly try it out.

  3. Michael says:

    Nice – very handy to have. Also loving your browser detection script – works like a dream!

Leave a Reply

About Chris

Chris Schuld

Thank you for visiting my website. I use this site for a myriad of things: maintaining software I have open sourced, connecting with my readers and friends and documenting all of this little things "I wished I would have written down." You can read more about me or contact me.


thanks for visiting... happy coding

Recent Comments