Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wyświetlanie Czcionek Utf8 W Obrazku
piernik
post
Post #1





Grupa: Zarejestrowani
Postów: 65
Pomógł: 0
Dołączył: 9.07.2004

Ostrzeżenie: (0%)
-----


Tworzę dynamicznie obrazek - wykres. Legenda będzie w wielu językach - równiez w chińskim dlatego użyłem kodowania utf8.

Przy wyświetlaniu tekstu na obrazku pokazują mi się krzaczki zamiast np. polskich liter. Mozna jakoś przekonwertować te znaki by php wyświetlał je w utf8??
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
carramba
post
Post #2





Grupa: Zarejestrowani
Postów: 74
Pomógł: 0
Dołączył: 29.10.2003
Skąd: Toruń

Ostrzeżenie: (0%)
-----


w gd2 zeby wyswietlic znaczki trzeba przekonwertowac utf-8 na unicode
za pomca funkcj :

  1. <?php
  2.  
  3.  
  4. /*===============================================================================
  5. /* utf8ToUnicode = zamienia znaki utf8 na unicode
  6. /*===============================================================================
  7. /
  8. function utf8ToUnicodeEntities ($source) {
  9.    // array used to figure what number to decrement from character order value 
  10.    // according to number of characters used to map unicode to ascii by utf-8
  11.    $decrement[4] = 240;
  12.    $decrement[3] = 224;
  13.    $decrement[2] = 192;
  14.    $decrement[1] = 0;
  15.    
  16.    // the number of bits to shift each charNum by
  17.    $shift[1][0] = 0;
  18.    $shift[2][0] = 6;
  19.    $shift[2][1] = 0;
  20.    $shift[3][0] = 12;
  21.    $shift[3][1] = 6;
  22.    $shift[3][2] = 0;
  23.    $shift[4][0] = 18;
  24.    $shift[4][1] = 12;
  25.    $shift[4][2] = 6;
  26.    $shift[4][3] = 0;
  27.    
  28.    $pos = 0;
  29.    $len = strlen ($source);
  30.    $encodedString = '';
  31.    while ($pos < $len) {
  32.  $asciiPos = ord (substr ($source, $pos, 1));
  33.  if (($asciiPos >= 240) && ($asciiPos <= 255)) {
  34.  // 4 chars representing one unicode character
  35.  $thisLetter = substr ($source, $pos, 4);
  36.  $pos += 4;
  37.  }
  38.  else if (($asciiPos >= 224) && ($asciiPos <= 239)) {
  39.  // 3 chars representing one unicode character
  40.  $thisLetter = substr ($source, $pos, 3);
  41.  $pos += 3;
  42.  }
  43.  else if (($asciiPos >= 192) && ($asciiPos <= 223)) {
  44.  // 2 chars representing one unicode character
  45.  $thisLetter = substr ($source, $pos, 2);
  46.  $pos += 2;
  47.  }
  48.  else {
  49.  // 1 char (lower ascii)
  50.  $thisLetter = substr ($source, $pos, 1);
  51.  $pos += 1;
  52.  }
  53.  
  54.  // process the string representing the letter to a unicode entity
  55.  $thisLen = strlen ($thisLetter);
  56.  $thisPos = 0;
  57.  $decimalCode = 0;
  58.  while ($thisPos < $thisLen) {
  59.  $thisCharOrd = ord (substr ($thisLetter, $thisPos, 1));
  60.  if ($thisPos == 0) {
  61.  $charNum = intval ($thisCharOrd - $decrement[$thisLen]);
  62.  $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
  63.  }
  64.  else {
  65.  $charNum = intval ($thisCharOrd - 128);
  66.  $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
  67.  }
  68.  
  69.  $thisPos++;
  70.  }
  71.  
  72.  if ($thisLen == 1)
  73.  $encodedLetter = \"&#\". str_pad($decimalCode, 3, \"0\", STR_PAD_LEFT) . ';';
  74.  else
  75.  $encodedLetter = \"&#\". str_pad($decimalCode, 5, \"0\", STR_PAD_LEFT) . ';';
  76.  
  77.  $encodedString .= $encodedLetter;
  78.    }
  79.  
  80.    return $encodedString;
  81. }
  82. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 10.10.2025 - 22:53