echo '<ul>'; foreach ($textArray as $index => $text) { if (!empty($text)) { echo '<li> ' . htmlspecialchars($text) . '</li>'; } } echo '</ul>';
<form action="guestbook.php" method="post"> <input type="text" name="userText" placeholder="Enter text"> <button type="submit" name="submit">Submit</button> </form> <!-- PHP code to handle form submission --> <?php if (isset($_POST['submit'])) { $text = $_POST['userText'] . PHP_EOL; file_put_contents($file, $text, FILE_APPEND); header("Location: guestbook.php"); // Redirect to refresh the page and display updated text } ?>