我正在使用一小段代码通过 PHP 生成静态 html 页面。
这是代码:
<?php
ob_start();
file_put_contents('someName.html', ob_get_contents());
// end buffering and displaying page
ob_end_flush();
?>
上面的代码工作正常,它将创建 html 页面 (someName.html)。
我想要做的是将 html 的名称从“someName”.html 更改为 PHP 输出。PHP 页面是一个动态的 PHP 页面,它将根据用户通过 html 表单请求的内容显示一些结果。
例如:用户在输入框中输入 2,创建的 html 页面将是 2.html 而不是 someName.php。
我确实尝试过这样的事情,但没有奏效:
<?php
ob_start();
file_put_contents($usersInput'.html', ob_get_contents());
// end buffering and displaying page
ob_end_flush();
?>
有谁知道我需要怎么做?
编辑:
我现在已经尝试过这种方式:
<?php
if (isset($_POST['userInput']))
{
file_put_contents($_POST['userInput'].'.html', ob_get_contents());
}
// end buffering and displaying page
ob_end_flush();
?>
所以基本上用户在 html 表单的输入字段中输入 2 并且 html 文件应该称为 2.html。
我得到这个错误:
Warning: file_put_contents(2.html) [function.file-put-contents]: failed to open stream: No such file or directory on line 1156.
这是在第 1156 行:
file_put_contents($_POST['userInput'].'.html', ob_get_contents());