Add Error Checking - Assistance

Hello all. I am very new to PHP and am trying to create a form to allow the editing of a text file. Remember, only a text file can be used, so please don’t reference using a database, etc. The form must check to see if the data is correct with no spaces between strings of text and no blank lines between text entries. Also, no special characters are to be permitted at the beginning of lines. The text is simply a list of domain names. I am including my rudimentary code and would enjoy others’ take on this. Thank you!


<?php require('/var/www/html/sas.php'); $url = ''; $file = '/var/www/html/usce88rt3'; // check if form has been submitted if (isset($_POST['text'])) { // save the text contents file_put_contents($file, $_POST['text']); // redirect to form again header(sprintf('Location: %s', $url)); printf('Moved.', htmlspecialchars($url)); exit(); } // read the textfile $text = file_get_contents($file); ?> <?php echo htmlspecialchars($text) ?>


Well, you can use preg_replace to remove any characters you don’t want.

Sponsor our Newsletter | Privacy Policy | Terms of Service