This is just
one of the many issues that might arise due to confusion over data representation.
CHAPTER 23 ?– B U ILDING WE B SITES FOR THE WORLD 599
You can eliminate such inconsistencies by localizing the information so that it appears
exactly as the user expects. PHP makes this a fairly easy task, done by setting the locale
using setlocale(), and then using functions such as money_format(), number_format(),
and strftime() per usual to output the data.
For example, suppose you want to render the renewal deadline date according to
the user??™s locale. Just set the locale using setlocale(), and run the date through
strftime() (also taking advantage of strtotime() to create the appropriate timestamp)
like this:
setlocale(LC_ALL, 'it_IT');
printf("Your subscription ends on %s", strftime('%x', strtotime('2008-03-
04'));
?>
This produces the following:
Your subscription ends on 04/03/2008
The same process applies to formatting number and monetary values. For instance,
while the United States uses a comma as the thousands separator, Europe uses a
period, a space, or nothing at all for the same purpose. Making matters more confusing,
while the United States uses a period for the decimal separator, Europe uses a comma
for this purpose. Therefore the following numbers are ultimately considered identical:
??? 523,332.98
??? 523 332.98
??? 523332.98
??? 523.
Pages:
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685