export page in html

Discussion in 'PHP' started by superst3, Sep 22, 2006.

  1. #1
    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
     
    superst3, Sep 22, 2006 IP
  2. discoverclips

    discoverclips Peon

    Messages:
    491
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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
     
    discoverclips, Sep 22, 2006 IP
  3. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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.
     
    clancey, Sep 23, 2006 IP
  4. intoex

    intoex Peon

    Messages:
    414
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    why not to use pre tag? and make a modification to make it 80 chars width?
     
    intoex, Sep 24, 2006 IP