Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][PHP] Pobrane dane nie maja PL czcionki
Forum PHP.pl > Forum > Przedszkole
sci201
Witam. Moj problem pewnie jest banalny no ale siedze i nie widze błedu :/ . A mianowicie cała strona jest ok posiada PL czcionke ale dane pobrane z bazy nie maja PL czionki po za "ó" i "ż" . W bazie danych zminialem zgodnie z artykulem "
  1. http://php.pl/phppl/Wortal/Artykuly/Pomysly-porady-sugestie-dobre-nawyki/Polskie-znaki-a-MySQL
// dane w bazie sa prawdło zpaisane z PL czcionka //

zrzut tabeli z kotrej sa pobierane :
  1. -- phpMyAdmin SQL Dump
  2. -- version 3.4.9
  3. --
  4. -- Host: localhost
  5. -- Czas wygenerowania: 20 Mar 2012, 14:37
  6. -- Wersja serwera: 5.0.91
  7. -- Wersja PHP: 5.2.17
  8.  
  9. SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
  10. SET time_zone = "+00:00";
  11.  
  12.  
  13. /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
  14. /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
  15. /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
  16. /*!40101 SET NAMES utf8 */;
  17.  
  18. --
  19. -- Baza danych: `morawiec_romic`
  20. --
  21.  
  22. -- --------------------------------------------------------
  23.  
  24. --
  25. -- Struktura tabeli dla `strony`
  26. --
  27.  
  28. CREATE TABLE IF NOT EXISTS `strony` (
  29. `id` int(11) NOT NULL AUTO_INCREMENT,
  30. `nazwa` text character SET utf8 collate utf8_polish_ci NOT NULL,
  31. `tresc` text collate utf8_unicode_ci NOT NULL,
  32. PRIMARY KEY (`id`)
  33. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=6 ;
  34.  
  35. --
  36. -- Zrzut danych tabeli `strony`
  37. --
  38.  
  39. INSERT INTO `strony` (`id`, `nazwa`, `tresc`) VALUES
  40. (1, 'O nas', '<p style="text-align: center">\r\n &nbsp;Tutaj tekst do wklejenia</p>\r\n<p style="text-align: center">\r\n &nbsp;</p>\r\n<p>\r\n i piszemy <u>podkreslnie</u> &nbsp;nie <strong>ma</strong></p>\r\n'),
  41. (2, 'Kontakt', '<p>\r\n &nbsp;</p>\r\n<p>\r\n Sklep<br />\r\n <br />\r\n ul.xxx<br />\r\n <br />\r\n 66-400 Gorz&oacute;w Wlkp.<br />\r\n <br />\r\n Telxxxx<br />\r\n <br />\r\n tel.kom 606 352 737<br />\r\n <br />\r\n emali: kontakt@xxx<br />\r\n <br />\r\n emali: xx</p>\r\n'),
  42. (3, 'Regulamin', '<p>\r\n Regulamin - tresc&nbsp;</p>\r\n'),
  43. (4, 'Oferta dla firm', '<p>\r\n Oferta dla firm</p>\r\n'),
  44. (5, 'Usługi ii łłł ńń óó', '<p>\r\n Usługi do uzupelnienia</p>\r\n');
  45.  
  46. /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
  47. /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
  48. /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


i zrzut kodu :

  1. <?
  2. $now=date("Y-m-d");
  3. $str = file_get_contents('CMSromic/cfdt.php', true);
  4. $cfgarray = unserialize(substr($str, 20));
  5. function Utf8ToIso($str)
  6. {
  7. return iconv("utf-8", "iso-8859-2", $str);
  8. }
  9.  
  10. // Konwersja ISO-8859-2 -> UTF-8
  11. function IsoToUtf8($str)
  12. {
  13. return iconv("iso-8859-2", "utf-8", $str);
  14. }
  15. $host = $cfgarray[2];
  16. $user = $cfgarray[3];
  17. $pass = $cfgarray[4];
  18. $db = $cfgarray[5];
  19.  
  20. $connection = mysql_connect($host, $user, $pass) or die ("unable to connect!");
  21.  
  22. mysql_select_db($db) or die ("unable to select database!");
  23.  
  24. $quest = "SELECT * FROM `konfiguracja` where 1";
  25. $do = mysql_query($quest);
  26. while ($wiersz = mysql_fetch_array($do))
  27. {
  28.  
  29. $ramka = $wiersz[1];
  30. $ty = $wiersz[0];
  31.  
  32. }
  33.  
  34.  
  35. ?>
  36. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  37. <html xmlns="http://www.w3.org/1999/xhtml">
  38. <head>
  39.  
  40. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  41. <title><?php echo"$ty";
  42. ?></title>
  43. <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
  44. </head>
  45. <body>
  46. <!-- Wrapper Starts -->
  47. <div id="wrapper">
  48. <!-- Header Top Starts -->
  49. <div id="header-top">
  50. <img src="images/logo.JPG" width="394" height="195" align="bottom" />
  51. </div>
  52.  
  53. <!-- Header Top Ends -->
  54. <!-- Header Starts -->
  55. <div id="header">
  56. <!-- Banner Starts -->
  57. <div id="banner">
  58. <div class="text">
  59.  
  60. <p>
  61. <?php
  62. echo "$ramka";
  63. ?>
  64. </p>
  65.  
  66.  
  67. </div>
  68.  
  69. </div>
  70.  
  71. <div id="menu">
  72. <ul>
  73. <li><a href="index.php" class="current"><span>Strona Głowna</span></a></li>
  74. <li><a href="index.php?action=onas"><span>O nas</span></a></li>
  75. <li><a href="index.php?action=uslugi"><span>Usługi</span></a></li>
  76. <li><a href="index.php?action=oferta"><span>Oferta dla firm</span></a></li>
  77. <li><a href="index.php?action=regulamin"><span>Regulamin</span></a></li>
  78. <li><a href="index.php?action=kontakt"><span>Kontakt</span></a></li>
  79. </ul>
  80. </div>
  81. <!-- Menu Ends -->
  82. </div>
  83.  
  84. <div id="container-wrapper">
  85.  
  86. <div id="container" class="clearfix">
  87.  
  88. <div id="mainarea">
  89. <?
  90.  
  91.  
  92. if($_GET[action]=="")
  93. {
  94. ?>
  95.  
  96. <div class="block1 floatleft">
  97. <h4>O nas:</h4>
  98. <div>
  99. <img src="images/img1.jpg" alt="image1" />
  100. <p>O naO n.</p>
  101. <p>O naO </p><p>
  102. <a href="#">czytaj wiecej...</a></p>
  103. </div>
  104. </div>
  105.  
  106. <div class="block1 floatright">
  107. <h4 class="green">Nasze usługi:</h4>
  108. <div>
  109. <img src="images/img2.jpg" alt="image1" />
  110. <p>Nasze usługi .Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi </p>
  111. <p>Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi Nasze usługi </p><p>
  112. <a href="#">czytaj wiecej..</a></p>
  113. </div>
  114. </div>
  115. <!-- Our Services Ends -->
  116. </div>
  117. <!-- Mainarea Ends -->
  118. <!-- Sidearea Starts -->
  119. <div id="sidearea">
  120. <!-- Recent Works Starts -->
  121.  
  122. <div class="block1">
  123. xxxxxx
  124. </div>
  125. </div>
  126. <!-- Recent Works Ends -->
  127.  
  128. <!-- Container Ends -->
  129. <!-- Footer Starts -->
  130.  
  131. <!-- Wrapper Ends -->
  132.  
  133. <?
  134. }
  135. else
  136. {
  137. include("$_GET[action].php");
  138. }
  139. ?>
  140. </div>
  141. </div>
  142. <div id="footer" class="clearfix">
  143. <p class="floatleft"><img src="images/footer-bg2.gif" width="960" height="14" alt="f" /><center>Copyright &copy; 2012<a href="xxx"> xxx<a></center></p>
  144.  
  145. </div>
  146.  
  147. </div>
  148.  
  149. </body>
  150. </html>
i podstrony ktorej jest wlasnie blad :
  1. <table width="98%"><tr><td>
  2. <?
  3.  
  4.  
  5. mysql_select_db($db) or die ("unable to select database!");
  6. $quest = "SELECT `nazwa`,`tresc` FROM `strony` WHERE `id`=5";
  7. $do = mysql_query($quest);
  8. while ($wiersz = mysql_fetch_row($do))
  9. {
  10. echo '<div class="mblock1"><h4 class="green">'.IsoToUtf8($wiersz[0]).'</h4>';
  11. echo"<div class='recent-works'>";
  12. echo IsoToUtf8($wiersz[1]);
  13. echo "</div></div>";
  14. }
  15. ?>
  16. </td></tr></table>


probowalem z
  1. mysql_query("SET NAMES utf8'");
  2.  
  3. mysql_query("SET CHARACTER_SET utf8_unicode_ci");
nic nie dalo
ferrero2
A masz strony html/php kodowane w UTF 8 ?
W zasadzie przy pobieraniu danych z MySQL trzeba sprawdzić.
Jak nie masz środowiska to np w notepad++
- rodzaj kodowania strony
- meta dane strony (ustaw na utf)
- wysylaj mysql_query("SET NAMES utf8'");
- sprawdź np w phpmyadmin ustawienia poszczegolnych tabel/widokow.

Po tym wszystkim powinno latać.

Pozdrawiam
VirG
Mam ten sam problem co kolega.
W <head> mam coś takiego:
Kod
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
<meta http-equiv='Content-Language' content='pl'>

przed head mam to:
Kod
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='pl' lang='pl'>


SET NAMES utf8 wysłałem do bazy danych i poustawiałem zapytaniami dla bazy i dla tabel utf8 (utf8_unicode_ci)
W notepadzie pokonwertowałem wszystko na utf8 (Format -> koduj w utf-8 albo konwertuj ....)

w bazie mam tak zapisane znaki:
ęóąśłżźćń~`!@#$%^&*()_-+=|\,<.>/?;:]}[{"
Wyświetla:
questionmark.gifquestionmark.gifquestionmark.gifquestionmark.gif?~`!@#$%^&*()_-+=|\,<.>/?;:]}[{"
Tylko to ó to ma taki inny pytajnik (w rombie)

I lipa -,- (server pod stronę mam zagraniczny)
fr33d0m
Utwórz nowy plik z poprawnymi nagłówkami i na początku menu: format -> koduj utf-8. Wczytaj tam coś z mysql i stawiam browara, że będzie po polsku. Miałem podobny problem z formatowaniem nawet po prze-konwertowaniu.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.