Hàm setlocale () trong PHP
Thí dụ
Đặt ngôn ngữ thành tiếng Anh Mỹ và sau đó quay lại mặc định một lần nữa:
<?php
echo setlocale(LC_ALL,"US");
echo "<br>";
echo setlocale(LC_ALL,NULL);
?>
Định nghĩa và Cách sử dụng
Hàm setlocale () thiết lập thông tin ngôn ngữ.
Thông tin ngôn ngữ là ngôn ngữ, tiền tệ, thời gian và các thông tin khác cụ thể cho một khu vực địa lý.
Lưu ý: Hàm setlocale () chỉ thay đổi ngôn ngữ cho tập lệnh hiện tại.
Mẹo: Thông tin ngôn ngữ có thể được đặt thành mặc định của hệ thống với setlocale (LC_ALL, NULL)
Mẹo: Để nhận thông tin định dạng số, hãy xem hàm localeconv () .
Cú pháp
setlocale(constant,location)
Giá trị tham số
Parameter | Description |
---|---|
constant | Required. Specifies what locale information should be set. Available constants:
|
location | Required. Specifies what country/region to set the locale information to. Can be a string or an array. It is possible to pass multiple locations. If the location is NULL or the empty string "", the location names will be set from the values of environment variables with the same names as the constants above, or from "LANG". If the location is "0", the location setting is not affected, only the current setting is returned. If the location is an array, setlocale() will try each array element until it finds a valid language or region code. This is very useful if a region is known under different names on different systems. Note: To view all available language codes, go to our Language code reference. |
Chi tiết kỹ thuật
Giá trị trả lại: | Trả về cài đặt ngôn ngữ hiện tại hoặc FALSE nếu không thành công. Giá trị trả về phụ thuộc vào hệ thống mà PHP đang chạy. |
---|---|
Phiên bản PHP: | 4+ |
Changelog: | PHP 5.3.0 - Nếu một chuỗi được truyền cho tham số hằng thay vì một trong các hằng LC_, hàm này sẽ ném ra một thông báo E_DREPRECATED. |
❮ Tham chiếu chuỗi PHP