在php文件中显示特殊字符


Displaying special characters in a php file

我在数据库中使用了各种欧洲字符(如ø, zie, ñ),但它们没有正确显示在我的php文件中。我在类似的问题中尝试了一些方法(如下),但没有一个有效。

<head>
  <meta charset="utf-ISO-8859-1">
  ...
</head>


<head>
  <meta charset="utf-8">
  ...
</head>


<?php
header('Content-Type: text/html; charset=ISO-8859-1');
echo "øąñ";
?>

<meta charset="utf-8">显示正确。如果你想从数据库中获取这些字符,可能你没有使用mysql set_charset函数。

$mysqli = new mysqli('localhost', 'user', 'password', 'database');
$mysqli->set_charset('utf8');