-1

To get escape chars working in my php code I use: header('Content-Type: text/plain'); but this is causing my html code to be displayed as plain text in my browser. How can I change the Content-Type back to text/html Tried switching the Content-Type from within my php code and from within the HTML code that follows it.

<?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>

I expected that the HTML code would be interpreted correctly by the browser but instead it is being displayed as plain text.

bigollo
  • 1
  • 1
  • 6
  • 2
    You can only have one content-type header in your code as shown - the HTML will by the way be invalid with a text-string before the – mplungjan Nov 01 '19 at 09:52
  • Does this answer your question? [How to insert spaces/tabs in text using HTML/CSS](https://stackoverflow.com/questions/9792849/how-to-insert-spaces-tabs-in-text-using-html-css) – 04FS Nov 01 '19 at 09:52
  • And insert your date in in a pre tag if you want the \t to render – mplungjan Nov 01 '19 at 09:54
  • And dir=ltr is default anyway – mplungjan Nov 01 '19 at 09:54

1 Answers1

0

You can only have one content-type header in your code as shown - the HTML will by the way be invalid with a text-string before the

I think you meant to do this

<?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>
mplungjan
  • 169,008
  • 28
  • 173
  • 236