{"id":35,"date":"2008-08-30T18:17:30","date_gmt":"2008-08-30T22:17:30","guid":{"rendered":"http:\/\/www.compdigitec.com\/labs\/?p=35"},"modified":"2008-08-30T18:17:30","modified_gmt":"2008-08-30T22:17:30","slug":"the-gtk-critical-gtk_text_buffer_emit_insert-assertion-warning-in-php-gtk2","status":"publish","type":"post","link":"http:\/\/www.compdigitec.com\/labs\/2008\/08\/30\/the-gtk-critical-gtk_text_buffer_emit_insert-assertion-warning-in-php-gtk2\/","title":{"rendered":"The &#8220;Gtk-CRITICAL gtk_text_buffer_emit_insert assertion&#8221; warning in PHP-GTK2"},"content":{"rendered":"<p>If your internationalized PHP-GTK2 apps have ever failed to work, you probably received the following message in the terminal before:<\/p>\n<p><strong><code>Gtk-CRITICAL **: gtk_text_buffer_emit_insert: assertion `g_utf8_validate (text, len, NULL)' failed<\/code><\/strong><\/p>\n<p>This means that you have been using or passing non-UTF8 (good chance that it is CP1252 on Windows) strings to PHP-GTK2 classes and methods, such as GtkWindow, GtkLabel or GtkTextBuffer. To fix this, you should use iconv to convert those non-UTF8 strings. Below is a list of commonly used encodings:<\/p>\n<ul>\n<li>English &#8211; UTF-8, windows-1252, ISO-8859-1<\/li>\n<li>Chinese, Simplified &#8211; GB2312<\/li>\n<li>Chinese, Traditional &#8211; Big5<\/li>\n<li>Spanish &#8211; ISO-8859-1, windows-1252<\/li>\n<li>French &#8211; windows-1252, ISO-8859-1<\/li>\n<li>German &#8211; windows-1252, ISO-8859-1<\/li>\n<li>Greek &#8211; windows-1253, ISO-8859-7<\/li>\n<li>Arabic &#8211; ISO-8859-6<\/li>\n<li>Hebrew &#8211; windows-1255<\/li>\n<li>Romanian &#8211; ISO-8856-16<\/li>\n<\/ul>\n<p>To use this list, take the encoding and put it in parameter 1. See below for examples:<br \/>\n<code><span style=\"color: #000000;\"><br \/>\n<span style=\"color: #0000bb;\">&lt;?php<\/span><\/span><\/code><\/p>\n<p><span style=\"color: #ff8000;\">\/\/\u00a0Convert\u00a0from\u00a0Chinese,\u00a0Simplified<br \/>\n<\/span><span style=\"color: #0000bb;\">$result <\/span><span style=\"color: #007700;\">= <\/span><span style=\"color: #0000bb;\">iconv<\/span><span style=\"color: #007700;\">(<\/span><span style=\"color: #dd0000;\">&#8220;GB2312&#8221;<\/span><span style=\"color: #007700;\">,<\/span><span style=\"color: #dd0000;\">&#8220;UTF-8&#8221;<\/span><span style=\"color: #007700;\">,<\/span><span style=\"color: #0000bb;\">$source<\/span><span style=\"color: #007700;\">);<\/span><\/p>\n<p><span style=\"color: #ff8000;\">\/\/\u00a0Convert\u00a0from\u00a0Greek<br \/>\n<\/span><span style=\"color: #0000bb;\">$result <\/span><span style=\"color: #007700;\">= <\/span><span style=\"color: #0000bb;\">iconv<\/span><span style=\"color: #007700;\">(<\/span><span style=\"color: #dd0000;\">&#8220;ISO-8859-7&#8221;<\/span><span style=\"color: #007700;\">,<\/span><span style=\"color: #dd0000;\">&#8220;UTF-8&#8221;<\/span><span style=\"color: #007700;\">,<\/span><span style=\"color: #0000bb;\">$source<\/span><span style=\"color: #007700;\">);<\/span><\/p>\n<p><span style=\"color: #ff8000;\">\/\/\u00a0Convert\u00a0from\u00a0Arabic<br \/>\n<\/span><span style=\"color: #0000bb;\">$result <\/span><span style=\"color: #007700;\">= <\/span><span style=\"color: #0000bb;\">iconv<\/span><span style=\"color: #007700;\">(<\/span><span style=\"color: #dd0000;\">&#8220;ISO-8859-6&#8221;<\/span><span style=\"color: #007700;\">,<\/span><span style=\"color: #dd0000;\">&#8220;UTF-8&#8221;<\/span><span style=\"color: #007700;\">,<\/span><span style=\"color: #0000bb;\">$source<\/span><span style=\"color: #007700;\">);<\/span><\/p>\n<p><span style=\"color: #ff8000;\">\/\/\u00a0Convert\u00a0from\u00a0French,\u00a0German,\u00a0and\u00a0other\u00a0Western\u00a0languages<br \/>\n<\/span><span style=\"color: #0000bb;\">$result <\/span><span style=\"color: #007700;\">= <\/span><span style=\"color: #0000bb;\">iconv<\/span><span style=\"color: #007700;\">(<\/span><span style=\"color: #dd0000;\">&#8220;windows-1252&#8221;<\/span><span style=\"color: #007700;\">,<\/span><span style=\"color: #dd0000;\">&#8220;UTF-8&#8221;<\/span><span style=\"color: #007700;\">,<\/span><span style=\"color: #0000bb;\">$source<\/span><span style=\"color: #007700;\">);<\/span><\/p>\n<p><span style=\"color: #0000bb;\">?&gt;<br \/>\n<\/span><\/p>\n<p>If, as an exception, that you don&#8217;t have the iconv extension (included on most PHP-GTK2 setups), you can change the php-gtk.codepage directive. However, this is not flexible and can only be used for one language.<\/p>\n<p>If you found this article helpful or useful, please help Compdigitec by spreading the word or by leaving a comment. Don&#8217;t forget to <a href=\"\/labs\/feed\/\">subscribe<\/a> to Compdigitec Labs for more interesting articles!<\/p>","protected":false},"excerpt":{"rendered":"<p>If your internationalized PHP-GTK2 apps have ever failed to work, you probably received the following message in the terminal before: Gtk-CRITICAL **: gtk_text_buffer_emit_insert: assertion `g_utf8_validate (text, len, NULL)&#8217; failed This means that you have been using or passing non-UTF8 (good chance that it is CP1252 on Windows) strings to PHP-GTK2 classes and methods, such as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[164,161,165,171,162,163,169,166,167,170,168],"_links":{"self":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/35"}],"collection":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/comments?post=35"}],"version-history":[{"count":0,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/35\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/categories?post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/tags?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}