PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



Sample Code 175: How to display non English characters in php gtk2 - Part 5 - Japanese on windows?
Written by kksou   
Monday, 19 February 2007
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   
<?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

  • Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
  • Registration is free and immediate.
  • Have some doubt about the registration? Please read this forum article.
Explanation
  1. You can mix Japanese characters freely with English characters.
  2. If you are displaying Japanese characters on a Japanese windows, you do not need this line. However, if you are using English windows, you need this line to display Japanese characters correctly.

Related Links

User reviews

There are no user reviews yet.

Note: You have to be a registered member to leave a comment. Free registration here.

 
< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2008. kksou.com. All Rights Reserved