请注意,我经常阅读类似的问题和建议的答案 弹出:
<?php
header("Content-Type: text/html; charset=utf-8");
?>
没有解决问题。
这是我的外页标题:
<!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=iso-8859-1" />
...
这是inner.php的示例
<p>£</p>
<p><?php echo $employee->salary; ?></p> <!-- employee->salary = £30,000 (from db) -->
我正在使用 jquery 加载:
$('#salary').load('inner.php')
在我看到的外部页面的输出上:
£
�30,000
inner.php 在控制台中查看时如下所示:
£
£30,000
我需要外页上的输出显示为 £30,000,但我无法弄清楚我做错了什么
最佳答案
使用 utf8_decode
或 utf8_encode
并将其包装在数据库输出中:
<p><?php echo utf8_encode($employee->salary); ?></p>
也许您的数据库未提供 UTF-8 字符串。
如果您没有任何理由在您的网站上使用 ISO-8859-1 字符集,除了您无法控制的外部文本(实际上是 ISO-8859-1 编码),请在以下位置使用 UTF-8:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
关于javascript - jQuery加载字符编码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24048607/