<?php
if (isset($_POST['page_content'])){
    // To create/overwrite the text file
    $textFile = fopen("page.txt","w+b");
    // To load the content of the text box and format it accordingly
    $content = $_POST['page_content'];
    $content = htmlentities($content,ENT_QUOTES); 
    $content = str_ireplace("\\"",""",$content);     
    $content = str_ireplace("\\& #039;","& #039;",$content); //delete the spaces between the & and #039;
    $content = str_ireplace("<","<",$content); 
    $content = str_ireplace(">",">",$content); 
    // Writes the new content to the file
    fwrite($textFile,$content);
    // Closes the file writing session
    fclose($textFile);
} else {
    // Checks to see if text file exists, and exit if it doesn't
    if (!(file_exists('page.txt'))) {
        exit('Failed to open page.txt.');
    }
}
// Grabs the content of the text file, and formats it accordingly (again!) 
$content = "<p>".file_get_contents("page.txt")."</p>";
$content = str_ireplace("\r\n","</p><p>",$content);
// Displays the formatted test
echo $content; 
?>