我有四个文本文件,我想显示它在浏览器上使用按钮,我想创建四个按钮时,点击第一个按钮,第一个文本应该打开。请帮我摆脱这个我是新的HTML和PHP。
最佳答案
为此,您需要阅读php文件函数。
请参阅此链接-http://php.net/manual/en/function.file.php
请尝试以下代码:
<h2>Click</h2>
<form action="" method="post">
<button name="click" class="click">Click me!</button>
</form>
<?php
if(isset($_POST['click']))
{
$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-->
<?php
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>";
}
?>
您可以将文件名替换为“test.txt”,因为我只是给您举个例子。
关于php - 如何在html中单击按钮时显示文本文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40394168/