*/}}

chatgpt_test.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. // Set the filename for the blog data
  3. $filename = "blog.txt";
  4. // Check if the file exists and create it if it doesn't
  5. if (!file_exists($filename)) {
  6. $file = fopen($filename, "w");
  7. fclose($file);
  8. }
  9. // Read the current blog data from the file
  10. $data = file_get_contents($filename);
  11. // If a new post was submitted, append it to the current blog data
  12. if (isset($_POST['new_post'])) {
  13. // Format the current time and date
  14. $timestamp = date("m/d/Y H:i:s");
  15. // Convert newline characters to <br> elements and remove the newlines
  16. $post = str_replace("\n", "", nl2br($_POST['new_post']));
  17. // Append the timestamp and the post content to the data
  18. $data .= "$timestamp: $post\n";
  19. file_put_contents($filename, $data);
  20. }
  21. // Set the CSS styles inline on the body element
  22. echo "<body style='margin: 0 auto; width: 80%; text-align: center;'>";
  23. // Display the blog posts in a list
  24. echo "<ul>";
  25. foreach (explode("\n", $data) as $post) {
  26. echo "<li>$post</li>";
  27. }
  28. echo "</ul>";
  29. // Display a form for creating new posts
  30. echo '<form action="" method="post">';
  31. echo '<textarea name="new_post" rows="5" cols="50"></textarea><br>';
  32. echo '<input type="submit" value="Submit">';
  33. echo '</form>';
  34. // Close the body element
  35. echo "</body>";