how to generate html from php?

Discussion in 'PHP' started by ronnyrtg, Jul 31, 2007.

  1. #1
    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?:confused:
     
    ronnyrtg, Jul 31, 2007 IP
  2. theanand

    theanand Active Member

    Messages:
    603
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #2
    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
     
    theanand, Jul 31, 2007 IP
  3. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #3
    <?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 ;)
     
    krt, Jul 31, 2007 IP
  4. nagasharmi

    nagasharmi Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    you just give extension of the file .html
    but phpfunciton would work
     
    nagasharmi, Jul 31, 2007 IP
  5. ronnyrtg

    ronnyrtg Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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.:)
     
    ronnyrtg, Jul 31, 2007 IP
  6. ronnyrtg

    ronnyrtg Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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?:confused:
     
    ronnyrtg, Jul 31, 2007 IP
  7. ronnyrtg

    ronnyrtg Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yipee!I pasted this code to the page1.php and it finally generated an html file with any text sent by the form!:eek: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!!!:p
     
    ronnyrtg, Jul 31, 2007 IP
  8. pfek

    pfek Member

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #8
    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.
     
    pfek, Aug 1, 2007 IP
  9. nagasharmi

    nagasharmi Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    you will try htaccess concept
    httpaccess used to change a file in differnt file name.
    there you change file name .html
     
    nagasharmi, Aug 2, 2007 IP