Prev | Current Page 399 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

93.
However, other parts of the world use different date and time formats, currencies, and
even character sets. Given the Internet??™s global reach, you may have to create an application
that??™s capable of adhering to foreign, or localized, formats. In fact, neglecting
to do so can cause considerable confusion. For instance, suppose you are going to
create a Web site that books reservations for a hotel in Orlando, Florida. This particular
hotel is popular among citizens of various countries, so you decide to create several
localized versions of the site. How should you deal with the fact that most countries
use their own currency and date formats, not to mention different languages? While
you could go to the trouble of creating a tedious method of managing such matters, it
likely would be error-prone and take some time to deploy. Thankfully, PHP offers a
built-in set of features for localizing this type of data.
PHP not only can facilitate proper formatting of dates, times, currencies, and such,
but also can translate the month name accordingly. In this section, you??™ll learn how to
take advantage of this feature to format dates according to any locality you please.
Doing so essentially requires two functions: setlocale() and strftime(). Both are
introduced next, followed by a few examples.
Setting the Default Locale
The setlocale() function changes PHP??™s localization default by assigning a new
value.


Pages:
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411