Php Utf8 Not Displaying Chinese Characters Properly
I am trying to echo a chinese word in php from a table data but it seems it is not displaying properly Here's my code <
Solution 1:
Remove this line echo'<?xml version="1.0" encoding="utf-8"?>
. Then, rework your code to look like this (HTML5 compliant). Keep the note of the meta
attribute in header:
<!DOCTYPE html><htmllang="zh-Hans"><head><title>A Test Page</title><metacharset="utf-8"></head><body><?php// Start PHP code from here$value = "黄后乎";
echo$value;
?></body></html>
Note: The HTML lang
attribute can be used to declare the language of a Web page or a portion of a Web page. This is meant to assist search engines and browsers.
EDIT:
You have to specify the SQL`s result character encoding, by instructing the MySQL server, BEFORE your actual query, like this:
$query = odbc_exec($conn, "SET NAMES 'utf8'");
$query = odbc_exec($conn, "SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'");
//Your actual DB query$query = odbc_exec($conn, "SELECT * FROM member WHERE userid = ". (int) $ID);
//Note the `(int) $ID` section, this is in order to prevent SQL injection attack.
Solution 2:
<!DOCTYPE html><?php
header('Content-Type: text/html; charset=utf-8');
?><htmllang="zh-Hans"><head><title>A Test Page</title><head><title>A Test Page</title></head><body><?php$value = "黄后乎";
echo$value;
?>
Solution 3:
<!DOCTYPE html><htmllang="zh-Hans"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8" /><title>A Test Page</title><head><title>A Test Page</title></head><body><?php$value = "黄后乎";
echo$value;
?>
Post a Comment for "Php Utf8 Not Displaying Chinese Characters Properly"