开发者

How do I display foreign languages in my php file

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开发者_JS百科 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 .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜