PHP-GTK2 Newsletter
PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou
Sample Code 316: How to display html text using gtkhtml? |
|
Written by kksou
|
|
Friday, 31 August 2007 |
|
Problem With the new PHP-GTK2 beta release, it's now a breeze to display html text with the use of GtkHTML as shown below:

Solution Using GtkHTML is easy.
- We execute the built-in GtkHTML command with $gtkhtml->command($command_name);?>
- Then display the html text with $html->load_from_string($html_text)
However, if this is the first time you use GtkHtml, please take note of the following.
Then display the html text with $html->load_from_string($html_text)
However, if this is the first time you use GtkHtml, please take note of the following.
Important Note:
- This only works for PHP-GTK2 compliled with the additional library GtkHTML.
- For linux, you have to recompile php-gtk2 to include this library.
- For windows, you may refer to the article How to install PHP-GTK2 on windows. The latest beta release from official php-gtk2 website comes complete with GtkHTML.
- In the
php.ini, don't forget to add php-gtk.extensions = php_gtk_html2.dll to turn on GtkHTML.
- Lastly, the most "tricky" part in running GtkHTML is that to run this script, you have to use gconfd-2 | php script.php. If you have installed the beta release of PHP-GTK2 on windows as outlined in this article, you will find the program gconfd-2.exe in the root directory of php-gtk.
- In the event that you cannot get this sample code to work, I would suggest that you try to do a fresh install of the beta-release of PHP-GTK2 (details here). It should work out-of-the-box (just need to add
php-gtk.extensions = php_gtk_html2.dll in php.ini as explained above). Note that you can still keep your original copy of php-gtk2 while having this new version.
- You will most likely see the warning
(php.exe:5348): Gdk-WARNING **: gdkselection-win32.c:1068: OpenClipboard failed: Invalid window handle.. Not really sure how to fix this yet. The script seems to run ok, though.
Sample Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <?php $window = new GtkWindow(); $window->set_title($argv[0]); $window->set_size_request(400, 250); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox());
$html = new GtkHTML(); // note 1
$vbox->pack_start($html);
$html_text = "<h1>GtkHTML Demo</h1> <p><i>hello <font color=blue>world</font></i>, <b>gtkhtml!</b></p>
<table border=4> <tr><th>A</th><th>B</th></tr> <tr><td>a1.1</td><td bgcolor=#BAFFBF>b1.2</td></tr> <tr><td bgcolor=#BAFFBF>a2.1</td><td>b2.2</td></tr> </table>
<ul> <li>item 1</li> <li>item 2</li>
|
- 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
- Create a new GtkHTML.
- Display the html text.
Note
Understand this one first. We will try to build a browser using GtkHTML in the next article...
Related Links
User reviews Average user ratings: 3.5 (from 2 users) Note: You have to be a registered member to leave a comment. Free registration here. |
|
March 11, 2008 10:00pm
May 01, 2008 2:56pm