"; echo "

$page_title

"; if (isset($error)) { echo "

$error

"; } echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo ''; echo '
'; echo ''; exit; } // Display the blog page echo "$page_title"; echo "

$page_title

"; // Check if the form was submitted if (isset($_POST['submit'])) { // Get the post title and content from the form $title = trim($_POST['title']); $content = trim($_POST['content']); // Validate the input if (strlen($title) == 0) { $error = 'Please enter a post title.'; } else if (strlen($content) == 0) { $error = 'Please enter post content.'; } else { // Format the post data as a string to be saved to the file $post = "=== $title ===\n$content\n"; // Open the file in append mode and write the post data $fh = fopen($file_path, 'a'); fwrite($fh, $post); fclose($fh); } } // Open the file and read the posts $fh = fopen($file_path, 'r'); $posts = ''; while (!feof($fh)) { // Read each line of the file and append it to the posts string $line = fgets($fh); $posts .= $line; } fclose($fh); // Display the blog posts on the page echo $posts; // Display the new post form echo '

New Post

'; if (isset($error)) { echo "

$error

"; } echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo ''; echo '
'; // Display the HTML footer echo ''; ?>