将文本文件中的新行转换为html p标签[重复]

This question already has an answer here:

I'm creating a chat room online and was wondering how to take the output from my index.php file and display it as a new p tag. The index.php takes user input from a html textbox and adds that phrase to the txt file; adding a new line with a phrase every time. I was curious as to how I could detect that a new line has been started in my txt file and create individual p tags or little message boxes with the phrase inside. (Just like a webchat)...

Here's my index.php:

<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<title>Pretendr</title>
<font color='DCDCDC'>
<body bgcolor='233142'>
<form action="index.php" method="post">
<input type="text" name="chat" value="Type something here..."/>
<input type="submit" name="someAction" value="GO" />
</form>
<?php
    if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['someAction']))
    {
        func();
    }
    function func()
    {
 $txt = $_POST['chat'];
 $myfile = file_put_contents('chatData.txt', $txt.PHP_EOL , FILE_APPEND | LOCK_EX);  
    }
?>

<div><p><?php include('chatData.txt'); ?></p></div>
</body>
</font>
</head>
</html>

And here's my text output file "chatData.txt":

Hello World!
It's quite lonely here... :(
I wish this text wasn't smashed together!

But it shows up like this:

Hello World! It's quite lonely here... :( I wish this text wasn't smashed together!

Thanks!

</div>