首页 > 解决方案 > 为什么我的 utf8 在我的 php 页面中不起作用?

问题描述

我在这里搜索了很多答案,但 UTF8 仍然存在问题。“特殊”字母没有出现在我的浏览器中。我正在使用:php Designer 8 Wampserver 3.1.4_x86 MySQL 5.6 Navicat100_premium 我正在使用 Google

[这是我页面中出现的内容 那些“?” 都是“ççççççççç”

这是代码的开头:

<html>
<title> APPACDM </title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>
header('Content-type: text/html; charset=utf-8');
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">

标签: phphtmlmysqlwampservernavicat

解决方案


在我看来,一切都是错误的。如果这是一个嵌入了 PHP 的 HTML 页面,试试这个:

<?php
    header('Content-type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html>
<head>
    <title> APPACDM </title>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"/>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

注意:始终在任何 HTML 输出之前设置您的 PHP 标头响应。始终将 PHP 包装在 PHP 标记中,而不是像您的示例中那样纯文本。

请参见此处:PHP 标头命令

谢谢,

肖恩。


推荐阅读