【问题标题】:Why is PHP page not displaying in browser? [duplicate]为什么 PHP 页面不显示在浏览器中? [复制]
【发布时间】:2013-04-21 23:53:34
【问题描述】:

当我访问我的页面时,我得到一个空白显示和以下消息:

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

以下是相关代码:

<?php 
$errors = array();
$missing = array();
//check if the form has been submitted
if (isset($_POST['send'])) 
{
//email processing script
$to = '$_POST['email']';
$subject = 'Your Quote';
$expected = array('email',);
$required = array('email');
$headers .= 'Content-Type: text/plain; charset=utf-8';
require('./includes/processmail.inc.php');
if ($mailSent) {
header('Location: http://www.dailyspiro.com/email.php');
exit;
}
}       
?>

<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    <meta content="utf-8" http-equiv="encoding"> 

【问题讨论】:

标签: php html


【解决方案1】:

不要使用元标记来声明编码,而是尝试使用标准文档类型,例如

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 

【讨论】:

  • &lt;!DOCTYPE html&gt; 一个标准的文档类型——它是从 HTML5 开始使用的文档类型。
  • 当然可以,但我的意思是为什么不尝试几年来一直是标准的东西呢?只有在遇到问题时,首先找到更广泛使用和接受的东西才有意义。
  • 你就是那种对一个完全有用的答案投反对票的人,哈哈。
  • 根本不是一个有用的答案。 HTML5 有效的文档类型声明已经存在。更不用说问题在于字符编码而不是 !DOCTYPE 声明。你甚至是 HTML 吗,兄弟?!
  • 哇,多么棒的评论。当然它已经存在了……告诉我,它实际上是 100% 工作的,而且是一个完整的标准吗,兄弟?!不,答案是否定的。
【解决方案2】:

在 PHP 代码顶部使用以下 PHP 标头

header('Content-type: text/html; charset=utf-8');

即。

<?php 
header('Content-type: text/html; charset=utf-8');
$errors = array();
$missing = array();
//check if the form has been submitted
if (isset($_POST['send'])) 
{
//email processing script
$to = '$_POST['email']';

【讨论】:

    猜你喜欢
    • 2014-05-07
    • 2020-06-18
    • 2019-06-12
    • 2017-06-29
    • 2013-03-15
    • 1970-01-01
    • 2017-11-01
    • 1970-01-01
    • 2011-05-01
    相关资源
    最近更新 更多