Menu

UTF8-Encoding

Character Encoding

This is a test of GD, Fonts, and character encoding. It does not use PHPlot but can be used to troubleshoot problems displaying extended characters in PHPlot text.

This is the output of the test script "chartest.php":

Chartest.php Output

This is the script "chartest.php". Caution: This script contains 3 extended characters encoded as UTF-8 on the line starting "RAW UTF-8 sequences". If you do not see single characters after the = signs, your editor, browser, or font is not configured for UTF8 character encoding.

::::php
<?php
# 2013-11-05 Test extended chars in strings with TTF fonts.

$text = array(
    'Testing extended chars',
    'Decimal numeric entities: Euro=&#8364; Cyr_DE=&#1044; Cyr_ZHE=&#1046;',
    "Embedded UTF-8 using escapes: Euro=\xe2\x82\xac Cyr_DE=\xD0\x94 Cyr_ZHE=\xD0\x96",
    # If you don't see the 3 special characters after the = signs below, you need to fix your
    # locale, font, or editor.
    "Raw UTF-8 sequences: Euro=€ Cyr_DE=Д Cyr_ZHE=Ж",
);
$width = 600;
$height = 400;
$pointsize = 14;

#$font = 'C:/Windows/fonts/tahomabd.ttf';
$font = '/usr/share/fonts/TTF/LiberationSans-Regular.ttf';

$im = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, $width-1, $height-1, $white);

$x = 10;
$y = 25;
$dy = 30;

foreach ($text as $s) {
  imagettftext($im, $pointsize, 0, $x, $y, $black, $font, $s);
  $y += $dy;
}
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);

Related

Discussion: Russian Language Title

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.