175. How to display non English characters in php gtk2 - Part 5 - Japanese on windows?

Problem

You want to display Japanese characters in php-gtk2 on windows as shown below:

How to display non English characters in php gtk2 - Part 5 - Japanese on windows?


Solution

  1. Open php.ini (located in the folder where you installed php-gtk2).
  2. Scroll to the bottom. Most likely you will see one big chunk of text like this.
  3. ;;;;;;;;;;;;;;;;;;;;;;; PHP-GTK extensions ;;;;;;;;;;;;;;;;;;;;;;;; Extensions written for PHP-GTK are in the format php_gtk_*.dll (Windows) or ;php_gtk_*.so (Unix), written here as a comma-separated list. The library ; files need to be in the same directory as the PHP-GTK library, along with; any other PHP extensions you are using. php-gtk.extensions = php_gtk_libglade2.dll ;;;;;;;;;;;;;; Code Page ;;;;;;;;;;;;;;; The string variables used for titles and other text values in GTK+ are; encoded in UTF-8 internally. A code page is needed so that PHP-GTK 'knows'; which character set is being used, and can convert it to UTF-8 as necessary.; If your environment uses UTF-8 already, you can set the codepage directive ; to UTF-8 to skip the conversions.; The default codepage setting in PHP-GTK 2 is ISO-8859-1, but you can also; use either OEM (e.g. 850) or Windows Code Pages (e.g. CP1250) here, so; long as the encoding format you choose is capable of iconv conversion. See; http://www.microsoft.com/globaldev/reference/cphome.mspx for a list of; the code pages and character sets that are supported on Windows systems.php-gtk.codepage = CP1250

    ; Local Variables:
    ; tab-width: 4
    ; End:

  4. Replace that chunk of text with the following:
  5. ;;;;;;;;;;;;;
    ; Code Page ;
    ;;;;;;;;;;;;;

    ; Japanese
    php-gtk.codepage = CP936

    ; note: if CP936 doesn't work, try CP932

  6. If you are running Japanese windows, you are all set. If you are running English windows, go to Control Panel - Regional and Language Options. Click on the Advanced Tab and make sure the Japanese language is installed.

Sample Code

1   
2   
3   
4   
5   
6   
7   
8   
9   
10   
11   
12   
<?php
$window = new GtkWindow();
$window->set_size_request(240, 120);
$window->connect_simple('destroy', array('Gtk','main_quit'));

$label = new GtkLabel("php-gtk2 ձZǤޤ!"); // note 1
$label->modify_font(new PangoFontDescription('ms gothic 10')); // note 2

$window->add($label);
$window->show_all();
Gtk::main();
?>

Output

As shown above.
 

Add comment


Security code
Refresh