Sample Code 270: How to display math and greek characters using symbol font - Part 3 - unicode characters in plain ANSI text file?
Written by kksou   
Tuesday, 19 June 2007
Problem

In Part 2, we have input math and greek characters as unicode characters on windows platform.

Suppose for some reason the php-gtk2 script has to be in plain ANSI text file, i.e. text file that does not allow any unicode or UTF-8 characters. (One example of this is the display php-gtk2 script that contains unicode characters on the web. Compare the sample code in Part 1 and Part 2 You will find that you can simply copy and paste the code for Part 1. But you cannot do so for Part 2. The unicode characters will end up as a bunch of garbage characters.)

In this Part 3, I will show you how to convert those math and greek characters (which are originally unicode characters) into urlencoded characters as shown below:

How to display math and greek characters using symbol font - Part 3 - unicode characters in plain ANSI text file?


Solution

Below are the steps to convert math/greek characters (which are originally unicode characters) into urlencoded characters:

  1. First you make an exact copy of the sample code from How to display math and greek characters using symbol font - Part 2 - input unicode characters?
  2. Enter one more line to convert $greek_str to urlencoded string:
  3. echo "urlencoded string = ".urlencode($greek_str)."\n";

    Your code should now looks like this:

  4. You will see the urlencoded string in the command window as shown below:
  5. Now all you need is to copy this urlencoded string into your php-gtk2 script, and use urldecode to convert the string back into the unicode characters as shown in note 1 below.
  6. Important Note: Once you have all unicode characters converted to urlencoded characters, you can save the php-gtk2 script as plain ANSI text file. You do not need to save this as UTF-8 file.

Sample Code
1   
2   
3   
4   
5   
6   
7   
8   
9   
10   
11   
12   
13   
14   
15   
16   
17   
18   
19   
20   
<?php
$window = new GtkWindow();
$window->set_size_request(400, 200);
$window->connect_simple('destroy', array('Gtk','main_quit'));
$window->add($vbox = new GtkVBox());

// display title
$title = new GtkLabel("Display Math and Greek Characters\n".
"using Symbol Truetype Font on windows\n".
"Part 3 - urlencode unicode characters");
$title->modify_font(new PangoFontDescription("Times New Roman Italic 10"));
$title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff"));
$title->set_size_request(-1, 60);
$title->set_justify(Gtk::JUSTIFY_CENTER);
$alignment = new GtkAlignment(0.5, 0, 0, 0);
$alignment->add($title);
$vbox->pack_start($alignment, 0, 0);
$vbox->pack_start(new GtkLabel(), 0, 0);

// display greek characters
  • 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

The sample code above is based on How to display math and greek characters using symbol font - Part 2 - input unicode characters?

What's new here:

  1. As explained above, we use urldecode to convert the urlencoded characters back to unicode characters.

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 >

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