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:
the variable is formatted incorrectly
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.