繁体   English   中英

header('Content-Type: text/plain');

[英]header('Content-Type: text/plain');

为了让转义字符在我的 php 代码中工作,我使用: header('Content-Type: text/plain'); 但这导致我的 html 代码在我的浏览器中显示为纯文本。 如何将 Content-Type 更改回 text/html 尝试从我的 php 代码和其后的 HTML 代码中切换 Content-Type。

<?php
      header('Content-Type: text/plain');
      echo 'Date Now:' . "\t" . date('m-d-Y') . "\n"; 
      header('Content-Type: text/html']);   
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
      <head>
             <title>date.php</title>
      </head>
      <body>
            ......
      </body>
</html>

我预计浏览器会正确解释 HTML 代码,但它会显示为纯文本。

如图所示,您的代码中只能有一个内容类型 header - HTML 在

我想你打算这样做

<?php
      header('Content-Type: text/html']);   
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <title>date.php</title>
  </head>
  <body>
    <pre>Date Now:<?= "\t". date('m-d-Y')."\n" ?></pre> 
  </body>
</html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM