hi i am a beginner and just started learning php.I was testing this code in a file called page1.php and its contents are <?php echo ("$uarea"); ?> which displays a text from a form in a file called index.php <form action="page1.php" method="post"> <textarea id="MyTextarea" name="uarea"></textarea> <input type="submit" value="Update"> </form> Question is,how can i generate an html file that has the same contents as page1.php?
PHP will be converted to HTML while it is being displayed in a browser. I am not sure if that is what you asked. If you view its source from the browser, it should be in HTML
<?php $fp = fopen('generated_file.html', 'w'); fwrite($fp, $_POST['uarea']); fclose($fp); ?> PHP: This will generate an HTML file, "generated_file.html", with the contents of the textarea, you might want to do some validation, such as stripping out JavaScript for security reasons, maybe even strip_tags() I hope that is close to what you wanted! It wasn't very clear
Yes i can view the HTML source but is there any php code that does exactly the same?From the limited knowledge that i have, the php code will give instructions to the server to generate the html code as we view them but i wanted to know if an actual html file can be generated after receiving feedback from the server.
if i change the page1.php into page1.html an error would occur the next time i submit the form: The requested method POST is not allowed I read somewhere in the net saying that html cannot accept data from the form in index.php.Any ideas?
Yipee!I pasted this code to the page1.php and it finally generated an html file with any text sent by the form!if i view the source code,that is the only text in the file and mozilla firefox would display just that.Thank you very much!! i love PHP!!!
I would use a preg_replace or str_replace and markers like ###FORM_NAME### to substitute in your loaded HTML content. That way, you will be able to use it again for other things. Might me a good way to let noobs use dreamweaver to "edit" the website, if you are working on a multi-user project.
you will try htaccess concept httpaccess used to change a file in differnt file name. there you change file name .html