未声明 HTML 文档的字符编码

2022-08-30 06:16:13

当我单击表单的提交按钮时,会出现以下错误消息:

未声明 HTML 文档的字符编码。在某些浏览器配置中,如果文档包含 US-ASCII 范围之外的字符,则该文档将使用乱码文本呈现。必须在文档或传输协议中声明页面的字符编码。

插入.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">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>insert page</title></head>
    <body>
    <h1> Insert Page </h1>
        <form action="insert.php" method="post"  enctype="application/x-www-form-urlencoded" >
         <p>Title:<input type="text" name="title" size="40" /></p>
         <p>Price:<input type= "text" name="price" size="40" /></p>
         <p><input type="submit" value="Insert" />
         <input type="reset" value="Reset" /></p>
        </form>    
    </body>
</html>

插入.php:

<?php
    $title = $_POST["title"];
    $price = $_POST["price"];

    echo $title;
?>

我不知道我的代码中哪里有问题。请帮帮我。


答案 1

将此内容作为第一行添加到 HTML 模板的 HEAD 部分中

<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">

答案 2

我在最基本的情况下遇到了同样的问题,我的问题通过将此标签插入文档的头部来解决:

<meta charset="utf-8">

未声明 html 文档的字符编码(实际上是 UTF-8)。

更多关于它在这里和这里


推荐