Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72358

Why is PHP printing code outside the semicolon?

$
0
0

I am writing some PHP code to display text from data.txt to the website. My code is:

<!DOCTYPE html>
<html lang="en" dir="ltr">

  <head>
    <link rel="stylesheet" href="style.css">
    <meta charset="utf-8">
  </head>
  <body>
    <?php
      //loading data
      $file = fopen("data.txt", "r") or die("unable to open!");
      $data = fread($file, filesize("data.txt"));
      echo "<p>" . $data . "</p>";
    ?>
  </body>
</html>

The output I'm getting is quite weird:

" . $data . ""; ?> 

The things that are wrong are:

  1. the variable is formatted incorrectly

  2. echo outputs everything but the HTML tags in the PHP script after it, although I ended it with a semicolon.

It is probably some stupid mistake, but what am I doing wrong?

Also, my data.txt isn't empty.


Viewing all articles
Browse latest Browse all 72358

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>