The code works in ANSI perfectly but when I change the encoding to utf8 the following error appears:
- Warning: Cannot modify header information – headers already sent by (output started at C:\xampplite\htdocs\alex.php:1) in C:\xampplite\htdocs\alex.php on line 2
–
<?php
header("Content-Type: image/png");
$im = @imagecreate(110, 20)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text Привет", $text_color);
imagepng($im);
imagedestroy($im);
?>
the output of the code must be the generated image with the sentence.
When I save it in utf8 without BOM a got completely different characters.
For example if i save it in utf8 without BOM the output of the script will be the following:

But I expect this sentence: “A Simple Text Привет”
You probably have a BOM (byte-order mark) at the start of the file. Since it’s at the very start, before the
<?phpopening tag, it’s output before your PHP code starts executing. Use an editor which allows you to create and edit UTF-8 files without BOM (for example, Notepad++).