I abstracted the header from a larger set of php files for clarity. When I load it into Wampserver, the <p>é</p> appears as � on the site, despite the header calling for utf-8 charset. What is wrong in this document?
(Note that I tried to modify the encoding by replacing iso-8859-1 with utf-8, that didn't help.)
header.php:
<?php
header('Content-Type:text/html; charset=UTF-8');
echo '<?xml version="1.0" encoding="iso-8859-1"?>'
?>
<!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="fr" lang="fr">
<head>
<title>Blabla</title>
</head>
<body>
<p>é</p>
</body>
</html>
try this<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> in the head section
and also check your file encoding
You are sending two contradicting character sets, iso-8859-1 and utf-8.
If you
fix that and send only one character set, and
encode the actual file in the character set you specify (there should be a character set option in your IDE's or editor's "Save as..." dialog)
it should work.
this worked for me :
I add to the MVC COntroller : produces={"application/json;charset=utf-8"}
Related
I am using ZF2 to send emails with UTF-8 encoding:
$message->setEncoding('UTF-8');
With such test content:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Test</title>
</head>
<body bgcolor="#FFFFFF">
ĄŚĆÓłąóźćżźęĄŚĆÓłąóźćżźęĄŚĆÓłąóźćżźę
</body>
</html>
Everything is correct in modern browsers or email clients. Problem is that old OutlookExpress doesn't recognize this. Message is displayed with ISO.
What should I do to make it read properly?
I found solution. When sending html the part have its own encoding. Setting UTF-8 there makes OE read message correctly.
$html = new Mime\Part($text);
$html->type = Mime\Mime::TYPE_HTML;
$html->charset = 'utf-8';
I guess OutlookExpress is able to show UTF8. But I experienced a situation where a client had a setting to force ISO encoding instead of detection from e-mail. So check the settings of outlookExpress.
Another thing which I would do is to send email from gmail with UTF8 encoding and read it in this OutlookExpress.
- Is it showed corectly? If yes, then look on the source of the mail and check what's different from yours. If not, then problem is probably in the OutlookExpress setings.
A weird thing when I use PHP Smarty.
It seems the encoding of php file affects the css.
PHP file (ANSI)--test2.php
<?php
include_once("inc/smarty_inc.php");
$smarty->display('test.tpl.htm');
Smarty file(ANSI)--test.tpl.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JPR</title>
</head>
<body>
<div style="width:500px;height:200px; background-color:Red;margin:auto;">
test
</div>
</body>
</html>
when these two files are ANSI. The div shows at the center of the page.(both IE and firefox)
when one of them is converted into utf-8. The div shows at the left of the page.(only in IE ,It's OK with Firefox)
What's the matter with it? How to make it OK in IE with uff-8?
You are saving the file in UTF-8 with BOM, this causes the first bytes in the response to be the bytes for byte order mark, and not doctype. When IE doesn't see doctype first, it goes to quirks mode, where the box model is different.
You need to convert it into UTF-8 without BOM. This depends on the text editor or converter you are using.
When I try to display letters of a foreign languages in my php file they show up as "?".
Anybody have any ideas how I can display them properly?
If I save the file as a HTML it displays the letter properly.
To add support for foreign characters you need to use UTF-8 (or any other similar encoding but UTF-8 is the most widely used) encoding.
text editing
At first you need to have your PHP/HTML files in UTF-8 encoding, use a text editor that supports this encoding, just check that the editor doesn't prepend UTF-8 BOM symbols to the file.
PHP
To serve your PHP files as UTF-8 (so the browser doesn't get mixed up about this) add relevant header
<?php header("Content-Type: text/html; Charset=UTF-8"); ?>
HTML
To serve your static HTML pages as UTF-8 use appropriate meta tag
<!-- with HTML5 -->
<meta charset="utf-8" />
<!-- or with older HTML formats -->
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
MySQL
To save/load UTF-8 encoded text in MySQL use the following statement after connecting to the MySQL server
<?php
mysql_connect(...);
mysql_set_charset('utf8');
?>
but check that the tables have also appropriate encodings set
+Using charset=utf-8
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
</head>
<body>
<body>
</body>
++ If you mention about open your php file .you have use an editor that support utf-8 something like this.
I am using Eclipse .
I am working on a php based site where some texts are greek and some are english. Greek texts are not showing correctly. The file is saved in UTF-8. Is there anything special to do in the header of the html page to show the greek text correctly? My header is like -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Also when I submit a form containing greek text, I am using -
$firstname = mysql_real_escape_string($_POST['firstname']);
Is this okay to use "mysql_real_escape_string" here?
Try the following:
Set the collation of your database/ tables/ rows to UTF-8. UTF8_general_ci should do.
Set the connection between MySQL and PHP to UTF-8. (By executing the query SET NAMES 'utf8' after connecting or by setting the default connection encoding).
Try sending the content-type header with PHP: header("Content-Type: text/html; charset=utf-8");.
As explained here (PHP Include and accents (They show up as �)) php has a strange behavior processing the accents. My question is Why?
I mean: I have a simple utf-8 charset page. With this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Title</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<?php include ('file.php');?>
The included file just says: "Administración." It has no charset, just header tags (h2, h3...), and some links. Like this:
<h2>Administración</h2>
So, there is no charset conflict. Are not they supposed that the include files are just included?
The previous question was answered with some fix to the problem, but my question is Why PHP behaves this way?
to answer you new questions (from your comment):
How can I do the same thing in other
editors, how do I know the default
charset?
default-charset and charset for every single file can be set in almost every code-editor i know - where exactly depends on the editor. simply take a look into the manual/documentation of your editor for that.