Doing a little of programming fun here.... I am writing a small script so I can write content easier, the script gets data from a form and using FWRITE it generates a file and writes the contents from the form into it. Its a very basic script, now here is where I am having trouble. When I generate the file example "test.html" I want to be able to include a TEMPLATE, so when it create the file the template is applied and the text is added to the BODY of the file. Right now I can generate: test.html and I can write PLAIN text to it, no html tags or anything. Any help will be highly appreciated. Thanks
Create a template file called template.php which has some content like my example below: <html> <head> <title>this is your template file</title> </head> <body> #body# </body> </html> PHP: When you submit the form do this within your processing: // Read the template into a variable $template = file_get_contents('/path/to/template.php'); // The add the form text to the file $contents = str_replace('#body#', $_POST['form_content'], $template); // Then you can write your $contents to the file with fwrite PHP: This will work although a better approach might be to save the body in separate files, and then add them to the template on the fly. That way if you ever need to adjust the template all the files are adjusted automatically. Hope this helps