PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



Sample Code 171: How to display non English characters in php gtk2 - Part 1 - simplied Chinese on windows?
Written by kksou   
Sunday, 18 February 2007
Problem

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

How to display non English characters in php gtk2 - Part 1 - simplied Chinese 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 ;
    ;;;;;;;;;;;;;

    ; Chinese simplified
    php-gtk.codepage = CP936

  6. If you are running simplified Chinese 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 Chinese language (simplified) 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 ÖÐÎÄÏÔʾ"); // note 1
$label->modify_font(new PangoFontDescription('simsun 12')); // 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 chinese characters freely with English characters.
  2. If you are displaying chinese characters on a chinese windows, you do not need this line. However, if you are using English windows, you need this line to display chinese characters correctly.

Related Links

User reviews   Average user ratings:    0.0   (from 4 users)
  1. rambo
    February 20, 2007 4:59am

    How do you save your scripts as when ever i try it kills the caticters and if i save a unicode text document php wont run it

  2. kksou
    February 20, 2007 9:02am

    If you have problem saving the above script, then just replace the chinese text above with any other chinese text.

    If you still have problem, please give a bit more details. E.g. what windows are you running? English windows? Simplified Chinese windows? Any error message displayed when you run the script?

  3. sanjeev from india
    June 04, 2007 12:18pm

    if i want to print hello world in chinese format what we have to do .plz explian neately with code that i can understand

  4. kksou
    June 15, 2007 6:38pm

    Which of the above steps do you find confusing? Which step did not work? What did you see on the screen? What's the error message. Please be more specific so that I know which part I need to elaborate on.

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

 
< Prev   Next >

Copyright © 2006-2008. kksou.com. All Rights Reserved