Skip to content

Using the internationalization (intl) extension in PHP

The internationalization (intl) extension in PHP provides tools for formatting and processing locale‑specific information. On ruachost.com, the intl extension is enabled by default, allowing developers to build applications that support multiple languages, regions, and cultural conventions.

  • Format dates, times, numbers, and currencies according to locale.
  • Handle text collation (alphabetical sorting rules differ by language).
  • Convert between uppercase and lowercase letters in different scripts.
  • Support multilingual applications with consistent formatting.

To view a list of locales supported on your server:

Terminal window
locale -a
  • Output will include codes like en_US (English, United States) or zh_TW.big5 (Chinese, Taiwan using Big5 encoding).
  • Format: xx_YY where xx = language code, YY = country/region code.
<?php
// Set locale to French (France)
setlocale(LC_ALL, 'fr_FR');
printRow();
// Set locale to English (United States)
setlocale(LC_ALL, 'en_US');
printRow();
// Function to display formatted output
function printRow() {
$number = 133.52;
echo "<tr>";
echo "<td>" . setlocale(LC_ALL, 0) . "</td>";
echo "<td>" . strftime('%c') . "</td>";
echo "<td>" . $number . "</td>";
echo "</tr>";
}
?>
  • In French: 133,52 (comma as decimal separator).
  • In English: 133.52 (period as decimal separator).
  • Date and time formats also differ by locale.

Some locales require specific character sets. For example, Cyrillic characters may not display correctly unless you specify encoding:

<?php
header('Content-Type: text/html;charset=iso-8859-5');
?>