TOC Previous Next
Overview
This section provides a brief overview of existing internationalization support in PHP 5, and then a description of each "layer" involved in providing PHP support in i5/OS and how it influences internationalization support.
PHP internationalization support
PHP 5 does not support Unicode, which makes internationalization support more complicated. According to Zend, this support will be added in the next release (PHP 6), but until then, it is necessary to find other ways to provide this functionality.
There is support for UTF-8 (see http://tools.ietf.org/html/rfc3629
for the detailed specification). You can find a good overview at http://en.wikipedia.org/wiki/Utf-8
. UTF-8 support is known as CCSID 1208 on i5/OS.
To configure PHP to use UTF-8 it is necessary to modify the php.ini file (found in \usr\local\Zend\Core\etc). Edit this file and add the following line under the existing (commented out) entry:
default_charset = "UTF-8";
This should enable pages written in languages such as English, Spanish, German, or French to continue working without change.
Layers on i5/OS
Given the way PHP support is implemented on i5/OS, there are several components that "touch" the data as it is passed between the browser and the actual PHP page under execution. It is very important to understand how each of these components influences national language support.
i5/OS
Traditionally, i5/OS has always been an EBCDIC-based machine. The vast majority of applications running on the box use data that is encoded in an EBCDIC-coded character set ID (CCSID). For a list of i5/OS-supported CCSIDs, visit:
http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/nls/rbagsccsidcdepgscharsets.htm
)
Many CCSID transformations can and do occur automatically when running applications under i5/OS. For example, Java is a Unicode-based language. When EBCDIC data is extracted from DB2 for i5/OS via the JDBC driver, an automatic transformation occurs from EBCDIC to Unicode. Many similar such transformations occur, often unbeknownst to the application developer and user.
PHP runs in the IBM i5/OS Portable Application Solutions Environment (PASE) under i5/OS. When an i5/OS PASE shell is created from i5/OS, many globalization-related configuration settings of the i5/OS job are passed to the i5/OS PASE environment.
For a full discussion of i5/OS globalization see:
http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/nls/rbagsglobalmain.htm
i5/OS PASE
The i5/OS PASE environment is an integrated runtime that makes it easy to run AIX applications from i5/OS. The following is a simplified view of how i5/OS PASE interacts with i5/OS and the System i hardware:
Figure 10-1 Simplified view of i5/OS PASE
PHP is implemented as an i5/OS PASE application that is initiated from i5/OS. Because of this, the i5/OS PASE environment that PHP runs in inherits its globalization from the i5/OS job that started it. For example, first issue the following command from i5/OS:
CHGJOB LANGID(RUS) CNTRYID(RU) CCSID(1025)
This changes the job's language and country IDs, and the job's CCSID to 1025 (which is the primary EBCDIC CCSID for Cyrillic).
Then start an i5/OS PASE terminal:
CALL PGM(QP2TERM)
As shown in Example 10-1, several globalization environment variables have been set automatically (in bold).
Example 10-1 Environment variables in new i5/OS PASE environment
We see that i5/OS PASE is running with CCSID 915, which happens to be one of the main ASCII CCSIDs for Cyrillic.
For a full discussion of i5/OS PASE, see:
http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/rzalf/rzalfintro.htm
PHP
The most important configuration parameter from a language perspective in PHP is the default_charset directive. Some plug-ins, such as the DB2 and ODBC drivers, use the value of this directive to determine what sort of data transformation is required.
This directive can be found in the php.ini file, which by default on i5/OS is located in the /usr/local/Zend/Core/etc directory. Setting this directive causes PHP to add the configured character set to be sent down to the browser in the Content-Type header.
Apache
For the most part, no special configuration of the Apache environments is required to modify globalization settings. The HTTP servers largely act as a "pipe," passing the PHP-generated data straight through.
If you use straight HTML files in addition to PHP files, you might have to make sure that the Content-Type header is set correctly. You can do this manually by adding the code to the header section of each HTML file:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
An alternate way to accomplish this is:
<?php
header('Content-Type: text/html; charset=utf-8');
?>
Note that this configuration is for UTF-8.
| Important: Make sure that your PHP file outputs the Content-Type header before any actual data intended for display is written out. In other words, you must do this within the header section and not the body. |
DB2 for i5/OS
Encoding character data in DB2 can be a complex topic. As mentioned previously, depending on the way the data is encoded in DB2 for i5/OS, and what format the consuming application wants the data in, transformations can occur.
Table 10-1 shows three ways to encode Russian (Cyrillic alphabet) data in DB2 for i5/OS.
Table 10-1 Ways of encoding Russian in DB2 for i5/OS
| Encoding |
SQL data type |
CCSID |
Description |
| EBCDIC |
CHAR/VARCHAR |
1025 |
EBCDIC Cyrillic Multilingual |
| UTF-8 |
CHAR/VARCHAR |
1208 |
Unicode, growing, represented as UTF-8 as defined in the Unicode Standard |
| Unicode |
GRAPHIC/VARGRAPHIC |
13488 |
Unicode UTF-16 as defined in the Unicode Standard |
We could create a single table containing columns of these data types using the DDL shown in Example 10-2.
Example 10-2 Creating table in i5/OS with three Russian character encodings
One way to populate the new table is by using the Operations Navigator database functions from a Windows workstation that has the Russian language installed (Control Panel > Regional and Language Options > Languages > Details... > Add).
There are two main methods of extracting data from DB2 for i5/OS into your PHP application, as detailed in Chapter 5, "Database access": using either the DB2 or the ODBC driver. As this book was being written, both of these drivers worked correctly with data encoded as detailed in Table 10-1. This occurred only after performing the configuration steps detailed in the next section.
TOC Previous Next