php 使用 UTF8 编码阿拉伯语
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18303255/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Encoding arabic using UTF8
提问by DrOsama
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
header.php - 包含 HTML 页面的第一部分(头部、元标记、JS 代码等)
page.php - 包含简单的 php 代码
页面内容
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.
在page.php、footer.php<head>
标签之间,否则阿拉伯文将无法正确支持。
This prevents page validation because of these tags.
由于这些标签,这会阻止页面验证。
Is there any method to avoid this problem ?
有什么方法可以避免这个问题吗?
Thanks
谢谢
回答by khaled.alshamaa
// 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">';
回答by Vin
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.
编码字符串阿拉伯成UTF-8使用工具这样。(无需更改任何设置 - 该链接具有您需要的正确设置)。
然后使用 utf8_decode() 将字符串解码回来。
Example:
例子:
<?php echo utf8_decode('your_encoded_string_goes_here'); ?>
回答by KAD
Apart from all of the answers... Make sure your (HTML/PHP) files are saved with the right encoding utf-8
除了所有的答案......确保您的(HTML/PHP)文件以正确的编码 utf-8 保存
回答by raj112
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
在您在页面中包含/include_once 的文件中
EDIT. example:
编辑。例子:
header.html
标题.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
<?php
include_once 'header.html';
?>
<p>
???????
</p>
<?php
include 'foot.html';
?>
foot.html
脚.html
<div>my footer</div>
</body>
</html>
回答by John Youssef
1- Put this
1-把这个
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
2- You should also save the documents in UTF-8 not ANSI
2- 您还应该将文档保存为 UTF-8 而不是 ANSI
回答by Basheer Hallak
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
您的标题应如下所示:
<!DOCTYPE html> <html lang="ar"> <head> <meta charset="utf-8"> </head> <body>
将文档另存为utf-8