Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP和HTML显示文件的内容_Php_Html_File - Fatal编程技术网

如何使用PHP和HTML显示文件的内容

如何使用PHP和HTML显示文件的内容,php,html,file,Php,Html,File,这就是我到目前为止在PHP方面所做的 <?php if (isset($_POST['submit'])) { $name = $_POST['name']; $file = fopen("names.txt", "a+"); fwrite($file,$name); fclose($file); $readFile = fopen("names.txt", "r"); fread($file); } ?> 如何在网页上显示从文

这就是我到目前为止在PHP方面所做的

<?php
if (isset($_POST['submit']))
{
    $name = $_POST['name'];
    $file = fopen("names.txt", "a+");
    fwrite($file,$name);
    fclose($file);

    $readFile = fopen("names.txt", "r");
    fread($file);
}
?>


如何在网页上显示从文件中读取的内容?

您可以用
echo$yourfile
更简单的方法

您还应使用:

这将通过一个命令读取文件并将其发送到浏览器。这与

echo file_get_contents("/path/to/file");
使用文件获取内容()


您应该
echo$yourfile
echo file_get_contents("/path/to/file");
$file = file_get_contents('names.txt', true);
echo $file;