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");.
Related
I am using CKEditor, i want to use Unicode and insert in database.
I copy the language and paste in CKEditor or input text and try to insert in database phpmyadmin. But I cannot get the desired output.
How to make my php website Unicode supportive. I am using HTML4 and i need to change my heading.
Here is my HTML
<!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" />
<meta charset="ISO-8859-1">
I m using phpmyadmin, and i change collations and set it to utf8_general_ci.
And That solve my problem.
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.
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 .
The problem:
An input of åäö in insert åäö in db. The file is in UTF-8 without BOM and comment in the table has utf8_general_ci coallition.
The code:
<?php
if($_POST['comment']!=''){
$comment=addcslashes($_POST['comment'], "\x00\n\r\'\x1a\x3c\x3e\x25");
if($kommentar!=''){
mysql_query("INSERT INTO comments (comment) VALUES ('$comment')") or die(mysql_error());
}
}
?><!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" lang="sv">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<body>
//Form
</body>
Background:
Earlier I performed htmlentities on the $_POST['comment']; before inserting to db, and outputted directly, which worked fine. Then I wanted to go best practise and input raw data (just cleaning) and o htmlentities (or similar) on output. But then I discovered that e.g. åäö is not inputted as åäö but as åäö. Heeeelp :)
You probably need to set the connection's collation to UTF-8, which is iso-8859-1 by default.
Try
mysql_set_charset("utf8");
after connecting to the database.
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"}