$str1 = ‘我是’;
imagettftext($target, 20, 0, 150, 70, $bc, $font, $this->to_entities($str1));
imagettftext($target, 20, 0, 210, 70, $cc, $font, $this->to_entities($userinfo[‘nickname’]));
public function to_entities($string){
$len = strlen($string);
$buf = “”;
for($i = 0; $i < $len; $i++){
if (ord($string[$i]) <= 127){
$buf .= $string[$i];
} else if (ord ($string[$i]) <192){
//unexpected 2nd, 3rd or 4th byte
$buf .= "�";
} else if (ord ($string[$i]) <224){
//first byte of 2-byte seq
$buf .= sprintf("&#%d;",
((ord($string[$i + 0]) & 31) << 6) +
(ord($string[$i + 1]) & 63)
);
$i += 1;
} else if (ord ($string[$i]) <240){
//first byte of 3-byte seq
$buf .= sprintf("&#%d;",
((ord($string[$i + 0]) & 15) << 12) +
((ord($string[$i + 1]) & 63) << 6) +
(ord($string[$i + 2]) & 63)
);
$i += 2;
} else {
//first byte of 4-byte seq
$buf .= sprintf("&#%d;",
((ord($string[$i + 0]) & 7) << 18) +
((ord($string[$i + 1]) & 63) << 12) +
((ord($string[$i + 2]) & 63) << 6) +
(ord($string[$i + 3]) & 63)
);
$i += 3;
}
}
return $buf;
}
[/php]