Question:
PHP :cannot print Japanese character (UTF) from MySQL?
Paradromer
2008-01-15 00:41:01 UTC
I inserted a row into my database in Japanese and some other UTF unicode character. It was successful in PHP MyAdmin ,every show up perfectly when I browse the table using the web interface. However, when I print them in my pHp page ,it give me "?????" instead. The English worked fine.
Three answers:
klip
2008-01-15 01:44:57 UTC
1. Server side:

Your table columns have to be set to utf (utf8_general_ci). This is very important (it is best to set utf8 for all databases as DEFAULT, so when you create any table and columns they are utf8). Not only database or table must be set to utf8, but the columns has to be set to utf8. If you have already any data in database, try to convert them by any encoding convertor, but usually all must be replaced when you change column's encoding from latin1 to utf, where data were tried to be saved as utf.



2. Client side:

In php you have to run a simple query after a connection to mysql, so server knows what encoding you accept the data in:

mysql_query("SET NAMES 'utf8'");



It is because php's mysql_connect sets the connection encoding to 'latin1'



3. Output:

Page has to conatin HTTP header stating that it is utf-8 encoded. So there are two ways



One is to add meta tag into header of html:





Or you can send the header by php:

header( 'Content-Type: text/html; charset=utf-8' );

(this has to be run before any output is sent, so put it at the very beginning of your php file, just after
Or you might try to call ob_start() at the beginning of your php file, then you can have headers anywhere in your code, because the output is buffered until it reaches the end of php script, or until you say to flush the buffer, and buffer also takes care of headers and flushes them before normal output)
RafaMinu
2008-01-15 00:54:44 UTC
MySQL Code Conversion algorithm — UCS-2 facilitates conversion between encodings. MySQL converts mappings to and from UCS-2. If client and server encoding are the same, there’s no conversion. If the conversion fails (ie, trying to convert to latin1), the character is converted to ? and you get mojibake.



Sheeri Kritzer has some great information about the Japanese Character Set.
anonymous
2016-12-02 04:45:56 UTC
Ergo Proxy: Re-L/actual Mayer Vincent regulation Iggy Raul Creed Daedalus Donov Mayer Hajime no Ippo Ricardo Martinez Alexander Volg Zangief Bryan Hawk Arnie Gregory Slam Dunk Michael Ghost interior the Shell Stand on my own complicated Marco Amereti Trigun Vash Stampede Meryl Stryfe Milly Thompson Million Knives finished steel Panic Teletha Testarossa Leonard Testarossa Gauron Melissa Mao Kurz Weber Gundam Wing Heero Yuy Duo Mazwell Trowa Barton Quatre Winner Chang Wu Fei Relena Peacecraft Zecks Marquise Gungrave Brandon warmth Harry Macdowell Ah My Goddess! Belldandy Skuld Urd Btx Karen Card Captor Sakura Mei Li Li Shau Ran Eriol Cooking grasp Boy Lan Fei Hung Liu Mao Shing Mei Li Shell dying word gentle Yagami Mihael Keehl Nate River Ray Penber Eden's Bowy Elissis very final delusion Cloud Rinoa Sephiroth Vincent Squall Flame of Recca Neon Galaxy Angels Vanilla Mint Milfeulle area of workmanship Rave grasp Elie Musica permit Julia gail Glory Gail Raregroove Lucia Raregroove Catleya Glory Plue Griffon Kato Ruby Sieg Hart Hunter x Hunter Biscuit Krueger Shalnark Feitan Bonolenov Franklin Legend of the Condor Heroes Xiao long Nu Yang Guo Guo Jing Hong Qi Gong Magic Knight Rayearth Lantis Emeraude Eagle inventive and prescient Monster Johan Liebert Anna Liebert Dieter Heckel Eva Heineman Wolfgang Grimmer Inspector Runge Martin Jan Suk Richard Braun Lotte Karl Schubert Franz Bonaparta generic Wolfe Roberto Ranma a million/2 Mousse Shampoo Cologne Rurouni Kenshin Lanz/Lantz Melderz Saber Marionette Lime Cherry Bloodberry Lux Panther Tiger Faust Shadow potential Elle Ragu Dias Ragu Scarface Darkness Kyou Kuo Fia/worry Arcana Vandread Meia Ezra Barnette Parfet Misty Magno Bart Duelo Voltes V vast Bert Little John Mark Steve Jaime Dr. Armstrong Prince Zardoz Cassandra (?) Daimos Erika Richard wedding ceremony Peach Aphrodite Limone Witch Hunter Robin Robin Sena Michael Lee Yami no Matsuei Eileen Dragon Ball Mr. devil Trunks Shaman King Anna El possibility Alielle Shayla-Shayla Slayers Lina Inverse Zelgadis Bubble Gum disaster Linna Nene Priscilla One Piece Zorro Luffy Robin Sorcerer Hunters Chocolate Marron Carrot Claymore Teresa Clare Galatea Noelle Priscila Miria Beth Alicia Jean Undine Uma Hellen Deneve Rubel (taken from Louvre) Rosemary Ophelia Irene flora those are from animes adapted from classic literature, uncertain in the event that they're component of what you're finding for.. Prince Cedie Cedie Becky Annie Mr. Habisham Princess Sarah Sarah Lotte Ermengaurde Lavinia pass over Minchin Amelia LIttle ladies Amy Beth Jo


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...