What does this function do? Oh, after converting the Chinese character into a UTF-8, you can use it in GD! SyntaxHighlighter. all (); info & nbsp; | & nbsp; Security & nbsp; | &
What does this function do? Oh, after converting the Chinese character into a UTF-8, you can use it in GD!
// Program writen by sadly www.phpx.com
Function gb2utf8 ($ gb)
{
If (! Trim ($ gb ))
Return $ gb;
$ Filename = "gb2312.txt ";
$ Tmp = file ($ filename );
$ Codetable = array ();
While (list ($ key, $ value) = each ($ tmp ))
$ Codetable [hexdec (substr ($ value,)] = substr ($ value );
$ Utf8 = "";
While ($ gb)
{
If (ord (substr ($ gb, 127)>)
{
$ This = substr ($ gb, 0, 2 );
$ Gb = substr ($ gb, 2, strlen ($ gb ));
$ Utf8. = u2utf8 (hexdec ($ codetable [hexdec (bin2hex ($ this)-0x8080]);
}
Else
{
$ Gb = substr ($ gb, 1, strlen ($ gb ));
$ Utf8. = u2utf8 (substr ($ gb, 0, 1 ));
}
}
$ Ret = "";
For ($ I = 0; $ I $ Ret. = chr (substr ($ utf8, $ I, 3 ));
Return $ ret;
}
Function u2utf8 ($ c)
{
For ($ I = 0; $ I $ Str = "";
If ($ c <0x80 ){
$ Str. = $ c;
}
Else if ($ c <0x800 ){
$ Str. = (0xC0 | $ c> 6 );
$ Str. = (0x80 | $ c & 0x3F );
}
Else if ($ c <0x10000 ){
$ Str. = (0xE0 | $ c> 12 );
$ Str. = (0x80 | $ c> 6 & 0x3F );
$ Str. = (0x80 | $ c & 0x3F );
}
Else if ($ c <0x200000 ){
$ Str. = (0xF0 | $ c> 18 );
$ Str. = (0x80 | $ c> 12 & 0x3F );
$ Str. = (0x80 | $ c> 6 & 0x3F );
$ Str. = (0x80 | $ c & 0x3F );
}
Return $ str;
}
Header ("Content-type: image/gif ");
$ Im = imagecreate (400,300 );
$ Bkg = ImageColorAllocate ($ im, 0, 0 );
$ Clr = ImageColorAllocate ($ im, 255,255,255 );
$ Fnt = "wb. ttf ";
// Include ("gb2utf8. php ");
$ Str = gb2utf8 ("China ");
ImageTTFText ($ im, 20, 0, 10, 20, $ clr, $ fnt, $ str );
ImageGif ($ im );
ImageDestroy ($ im );
?>