Hello! I am a newbie and a noob for php. I am trying to do some experiments with php and html. I have made a form that has 4 fields 1. Name of the file (ex. abc.html) 2. Heading 3. Subheading and 4. Content I am storing this data to mysql using a php file named store.php then I recall last saved data using another file named create.php this file creates a file with the name supplied in "Name of the file" field and writes Heading, Subheading and content data stored in mysql using fwrite. What I am trying to do is format this newly generated file with css and html. I want to display heading in <div class="heading"> Heading field data</div>, content data in <div class="content"> Data entered in content filed</div> and so on I am not getting any clue how to achieve it? Kindly help me I have read many manuals but found nothing.
If I understand you correctly, you want to create a file based on the values of 4 form fields?, if so... <?php $output = null; if (isset($_POST['submit'])){ //strip html...to avoid interference... $_POST = array_map('strip_tags', $_POST); $_POST = array_map('trim', $_POST); $name_of_file = $_POST['name']; $sub_heading_content = $_POST['sub_heading']; $heading_content = $_POST['heading']; $content = $_POST['content']; //validation... if (!preg_match('~^([a-z0-9\-]{3,})$~Di', $name_of_file)){ $output = "Invalid file name."; } elseif (strlen($sub_heading_content) < 2){ $output = "Your sub heading is too short."; } elseif (strlen($heading_content) < 2){ $output = "Your heading is too short."; } elseif (strlen($content) < 2){ $output = "Your content is too short."; } elseif (file_exists($name_of_file.'html')){ $output = "Please change your filename as it already exists."; } else { ob_start(); ?> <style type="text/css"> .heading{ /* style here */ } .subheading{ /* style here */ } .content{ /* style here */ } </style> <div class="heading"><?php echo $heading_content; ?></div> <div class="subheading"><?php echo $sub_heading_content; ?></div> <div class="content"><?php echo $content; ?></div> <?php $html = ob_get_clean(); $fp = fopen($name_of_file.'.html', 'w'); fwrite($fp, $html); fclose($fp); $output = "Success, <a href=\"{$name_of_file}.html\">click here</a> to view the file."; } } else { ?> <form method="post"> File Name:<br /><input type="text" name="name">.html<br /> Sub Heading:<br /><input type="text" name="sub_heading"><br /> Heading:<br /><input type="text" name="heading"><br /> Content:<br /><textarea name="content" style="width: 150px, height: 200px;"></textarea><br /> <input type="submit" name="submit" value="Submit"> <?php } echo (!is_null($output)) ? $output." <a href=\"javascript:history.go(-1)\">[Go Back]</a>" : $output; ?> PHP:
I have attached a txt file with all the codes I am using kindly take a look and see if any idea comes to your mind. Thanks for your reply!
Now a new problem has started. I am trying to include the list of last 10 or 20 links that have been created using script on the newly created page but I see a strange character  at the starting of the list. How can I remove it?