Anil Kumar Nelakuditi Anil Kumar Nelakuditi - 7 months ago 41
HTML Question

How to display Text file on clicking button in html

hi i have four text files and i want to display it on browser using buttons i want to create four button when click on 1st button first text should open. Please help me out from this i'm new to html and Php.


To do this you need to read about php file functions.

Refer this link -

Try below code:

<form action="" method="post">
    <button name="click" class="click">Click me!</button>

        $filename = "test.txt";
        $before_editing = file_get_contents($filename);

<!--this is for display in table-->
<table border="1"><tr><td><?php echo "Content of the file " . $filename . " before editing: " . $before_editing . "<br>"; ?></td></tr></table>
<!-- this is for display in single-->
        echo "Content of the file " . $filename . " before editing: " . $before_editing . "<br>";
        file_put_contents($filename, "test test test test test");
        $after_editing = file_get_contents($filename);
        echo "Content of the file " . $filename . " after editing: " . $after_editing . "<br>";

You can replace your file name to "test.txt" as i am just giving example to you.