Hi everybody. I want realize a php page with a botton that allow to export the same page in html format. Like the action of the browser menu file-->save page as Can you help me???? many thanks stefano
main file: <?php $send = $_POST['send']; if ($send == 1) { $rn = rand(1,1000); $adr = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; copy($adr, $rn . ".html"); $file = $rn . ".html"; echo "<script>window.location='down.php?id=" . $rn . "';</script>"; } else { ?> <form action="tryout.php" method="post"> <input type="hidden" name="send" value="1"><input type="submit" name="ok" value="ok"></form><?php } ?> Code (markup): down.php: <?php $r = $_REQUEST['id']; $h = $r . ".html"; header('Content-type: text/html'); header('Content-Disposition: attachment; filename=' . $r . '.html'); readfile($h); ?> Code (markup): let me know if that is what you're looking for
There is no reliable way to convert a plain text file into HTML format because of the difficulty in teaching a program to know that a line is a subhead instead of a paragraph or that a line should be treated like a table. I have tackled this problem in perl and found that you need to partially mark up documents to make it easier for a program to handle documents without futher intervention. The default treatment of a single line of text is to treat it as a paragraph. However, if the parser encounters certain HTML blocks, it stops tagging until it exits the block. For tables you could use <table> </table> tags to define the start and finish and not allow tagging until you are done with that section. The program also needs to convert characters which have special meaning in HTML into safe entities. This includes the angle brackets < and > You need to know if you want to convert it or leave it. A mathematical less than < needs to be seen as being different from the start of a valid html tag. This is an excellent project to learn about coding and text parsing. Good luck with it.