![](/img/trans.png)
[英]Is header('Content-Type:text/plain'); necessary at all?
[英]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.