用php创建.html文件 [英] Create .html file with php
问题描述
我想使用php脚本创建一个新的.html文件,因为我不了解php. 我创建了一个代码,但是没有用.
i want to create a new .html file using php script as i new to php i don't understand to do it. i founded a code but it m not working.
<?php
$filename = '/path/to/foo.html';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}?>
我希望在加载页面时,应在路径/目录中创建一个新的.html文件,并在其中添加一些条目,例如在html文件中添加标题e.t.c
i want that when i load my page, an new .html file should be created to my path/ directory with some entries like heading e.t.c in my html file
有人可以帮助我吗?
推荐答案
最好的方法是编写一个小的空白html文件并将其保存在某处;例如"template.html"
Best way to do it would be to write a small blank html file and save it somewhere; e.g. "template.html"
1)在PHP中,您可以使用
1) in PHP you can read it with
$newcontent = file_get_contents("template.html");
2)用fopen打开一个新文件,写入新内容,关闭该文件.完成.
2) the open a new file with fopen, write new content, close the file. Done.
if (!file_exists('newname.html')) { $handle = fopen('path/to/new/file/newname.html','w+'); fwrite($handle,$newcontent); fclose($handle); }
这篇关于用php创建.html文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!