UTF8 and Japanese characters

Problem: An external character is not displayed as it should. This includes German, Japanese, Russian, and everything else except English (works great). Ones PHP accesses MySQL through a jQuery AJAX call, it must return information and display it on the page. Data is called up and displayed. However, for non-English characters, the results are displayed as "?".

In phpMyAdmin, data is displayed as it should have been in Japanese, German ect ect. But those derived from MySQL are not returned as such.

The problem is not caused by the browser, as my browser supports encodings of all languages.

MySQL encoding: UTF8_GENERAL_CI

Page Encoding: UTF-8

<meta charset="utf-8" />

The problem may be retrieving PHP data from MySQL, since in MySQL it looks great, viewed through phpMyAdmin. So, here is the code used to extract this data from MySQL. If the encoding should not be included in this file.

view.php (selecting the necessary data from MySQL can cause an encoding error)

$q = mysql_query("SELECT * FROM `notice` WHERE nid = '".$nid."'");
         $a = mysql_fetch_array($q);

             $nid = stripslashes($a['nid']);
             $note = stripslashes($a['note']);
             $type = stripslashes($a['type']);
             $private = stripslashes($a['private']);
             $date = stripslashes($a['date']);
             $author = stripslashes($a['author'])

;

PS. Edited to be more clear.

+3
source share
3 answers

Most likely, you need to set the character set of your connection to the UTF-8 database.

How to do this depends on the database library used.

In the old mySQL library, this will be

mysql_query("SET NAMES utf8");

(pre mySQL 5.0.7) and

mysql_set_charset("utf8");

for mySQL 5.0.7 and later.

+5
source

try to call

mysql_query("SET NAMES utf8");

somewhere before your request. Of course, if you are in PHP.

0

See: http://www.w3.org/TR/html4/charset.html#h-5.2.2

So you should use: <META http-equiv="Content-Type" content="text/html; charset=UTF-8">

Ideally, this information should be provided in the headers of the HTTP response.

-1
source

All Articles