Hi guys I have an issue to display chinese character in simple php file, I cannot figure out how to get it solved
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<?php
define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-type" value="text/html; charset=UTF-8" />
</head>
<body>
电视机/電視機
</body>
</html>
I am think this can be the issue of apache or php.ini configuration. Any idea how to solve this issue?
Use <meta charset="utf-8"> before <title>
Some old style browers checks http header first, so you may set
<?php
header("Content-Type: text/html; charset=utf-8");
or change your web server config file
Example in Nginx:
add this lines after server {
charset utf-8;
charset_types
text/css
application/javascript
application/x-javascript
text/xml
text/plain;
Example in Apache:
AddDefaultCharset Off
or
AddDefaultCharset utf-8
Try using this:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
You write value instead of content
Cheers!
As you are using html5 you can use
<meta charset="utf-8">
and it will your fix issue.
If you are not using html5 then changing value to content will fix it
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
sorry did not get the question, but for thos who are getting the data from db try adding
mysql_query("SET NAMES 'utf8'"); in your db connection
Related
I'm trying to change my website from windows-1251 to utf-8, but it won't budge.
There are a ton of "solutions" to this on web, but any doesn't seem to be sufficient.
Here is what I did:
I changed the encoding of the index.html (smarty template) and index.php files to UTF-8.
I set
<html lang="ru">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
in index.html
I set
header('Content-type: text/html; charset=utf-8');
in several places in index.php
I changed
default_charset="UTF-8"
in php.ini and restarted my Apache(XAMPP) server
And still, the Chrome devtools say my page is "Content-Type: text/html; charset=windows-1251" and I see gibberish instead of Cyrillic in my browser.
What else can I do?
P.S. my index.html looks like this now:
<?php header('Content-type: text/html; charset=utf-8'); ?>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
Тест
</body>
</html>
and I open it dirrectly via the browser: http://localhost:8080/index.html
Check this url. This might help you.
charset changing
Edit:
Try these.
Set the header before HTML tags.
<?php header('Content-type: text/html; charset=utf-8'); ?>
<!DOCTYPE html>
when you connect your script to the database you need to specify the same character set for PHP/MySQL connection.
Check
Old issue
It appeared I had a Chrome encoding extension installed, which was set to Windows-1251: https://chrome.google.com/webstore/detail/set-character-encoding/bpojelgakakmcfmjfilgdlmhefphglae
My website runs in localhost without any errors; but when I added my site to CPpanel and run members.php page disapeared (it shows white background). Inspecting the page in console displays this error message :
The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.
Inspecting the element shows only these lines:
<div style="clear:both;"></div>
</div>
</div>
</body>
</html>
From the error you get, please add this to your <head> ... </head>:
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-5">
If the charset above did not work, please try this instead:
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
And I hope you defined the before BODY part of your pages as this:
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title> Your Title</title>
</HEAD>
<BODY>
....
EDIT 2:
Before including other any other PHP files in your members.php, type this line first:
header('Content-type: text/html; charset=utf-8');
Have you something like this in header? You put instead of utf-8 encoding of your file.
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
Currently I created simple website using include system
header.php - contains first part of HTML page (Head, meta tags, JS codes ... etc )
page.php - contains simple php code
page content
My main problem with arabic language
I have to put
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
in page.php, footer.php between <head> tags otherwise the arabic will not support correctly.
This prevents page validation because of these tags.
Is there any method to avoid this problem ?
Thanks
// Send a raw HTTP header
header ('Content-Type: text/html; charset=UTF-8');
// Declare encoding META tag, it causes browser to load the UTF-8 charset
// before displaying the page.
echo '<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />';
// Right to Left issue
echo '<body dir="rtl">';
Encode the arabic string into UTF-8 using a tool like this. (No need to change any settings - that link has the the correct settings you need).
Then use utf8_decode() to decode the string back.
Example:
<?php echo utf8_decode('your_encoded_string_goes_here'); ?>
Apart from all of the answers... Make sure your (HTML/PHP) files are saved with the right encoding utf-8
All you need is to put this
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
in a file that you include/include_once in your pages
EDIT. example:
header.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>my title in العربية</title>
</head>
<body>
mypage.php
<?php
include_once 'header.html';
?>
<p>
العربية
</p>
<?php
include 'foot.html';
?>
foot.html
<div>my footer</div>
</body>
</html>
1- Put this
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
2- You should also save the documents in UTF-8 not ANSI
Your headers should appear as the following:
<!DOCTYPE html>
<html lang="ar">
<head>
<meta charset="utf-8">
</head>
<body>
Save your document as utf-8
I'm trying to grasp UTF-8 and charset encoding in general, but it's tricky
This code:
<?php
header('Content-type: text/html; charset=utf-8');
?>
<!doctype html>
<html lang="da">
<head>
<title>UTF-8 test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div>
<p>UTF-8 æøå tést Señor!</p>
</div>
</body>
</html>
Outputs:
UTF-8 ��� t�st Se�or!
Same result on both local server and on multiple public sites (all Apache)
Do I need to change something in php? Or Apache? Or my text editor? (notepad++)
Your text editor isn't saving as UTF-8.
I think you should change the character encoding of your notepad++, you can change this under "Encoding" menu.
you can check your right corner of status bar for the encoding of your file.
How to display Korean Text in a webpage. i have been using these meta tags and headers
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="content-language" content="ko"/>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"/>
ini_set('default_charset', 'UTF-8');
header('Content-Type: text/html;charset=utf-8');
But nothing works.. please help!!
NOTE: I tried every tag 1 at a time not all at once.
Use:
ini_set('default_charset', 'UTF-8');
header('Content-Type: text/html;charset=utf-8');
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
and make sure your editor is configured to save using UTF-8, and make sure that any other systems involved (e.g. databases) are configured to use utf-8.
Your example has two META tags - one is UTF-8 and the other is ISO-8859-1.