[英]Is it possible to create an HTML page without the use of MySQL?
From what I have so far, I have an HTML form using method POST for PHP. 到目前为止,我已经有了使用PHP的POST方法的HTML表单。 What I want to do is automatically create a page using the input that includes a stylesheet and things that aren't in the form. 我想做的是使用包含样式表和表单中未包含内容的输入自动创建页面。 I know that it is possible to create an XML page like this, as I have, but can you make an HTML page? 我知道可以像这样创建一个XML页面,但是您可以创建HTML页面吗? Here is what I have so far, including the creation of the XML page and is creating an HTML page much like creating an XML page? 到目前为止,这就是我的工作,包括创建XML页面,创建HTML页面是否与创建XML页面非常相似?
HTML form: HTML形式:
<form action="insertpage.php" method="post" class="form">
Noun<input name="form1" value="" type="text">
Adjective<textarea name="form2" cols="40" rows="4"></textarea>
<input type="submit" value="Submit">
</form>
PHP creating XML file PHP创建XML文件
$xml = new DOMDocument("1.0");
$root = $xml->createElement ('root');
$xml->appendChild($root);
$form1 = $xml->createElement ('form1');
$vtext = $xml->createTextNode($_POST[form1]);
$form1->appendChild($vtext);
$root->appendChild ($form1);
$form2 = $xml->createElement ('form2');
$advtext = $xml->createTextNode($_POST[form2]);
$form2->appendChild($advtext);
$root->appendChild ($form2);
$xml ->save("words/$_POST[form1].xml"))) or die ("error creating file");
This works perfectly fine, except I cannot find a way to automatically create an HTML page with the user input. 这工作得很好,除非我找不到用用户输入自动创建HTML页面的方法。 Is there any way to do this with PHP because that would be perfect too. 有没有办法用PHP做到这一点,因为那也是完美的。 By the way, I know this method is terribly unsafe, and I am working on creating some security like captcha. 顺便说一句,我知道这种方法非常不安全,并且我正在努力创建一些验证码,例如验证码。 Also if you can't do this with PHP, is there any other programming language that can do this? 另外,如果您无法使用PHP执行此操作,是否还有其他编程语言可以执行此操作? Thank you 谢谢
Here's a pretty simple idea to get you started. 这是一个非常简单的想法,可以帮助您入门。
HTML Template: template.html (Very much trimmed down) HTML模板:template.html(已大大减少)
<div>
<p>[[name]]</p>
<p>[[email]]</p>
</div>
HTML Form: HTML表单:
<form action="whatever.php" method="post">
<input type="text" name="name" placeholder="name" />
<input type="text" name="email" placeholder="email address" />
<button>Create Page</button>
<input type="hidden" name="create_page" value="true" />
</form>
PHP Script: PHP脚本:
<?php
if (isset($_POST['create_page']))
{
$template = file_get_contents('template.html');
$template_vars = array(
'name' => $_POST['name'],
'email' => $_POST['email']
);
foreach ($template_vars as $k => $v)
{
$template = str_replace("[[{$k}]]", $v, $template);
}
file_put_contents('newfilename.html', $template);
}
Hope that helps. 希望能有所帮助。
It's worth mentioning that this is open to malicious user input, you should sanitize all the post data, this is just a very quick example. 值得一提的是,这对恶意用户输入是开放的,您应该清除所有发布数据,这只是一个非常简单的示例。
只需将<?php echo $_POST['form1'];... ?>
标记与<input>
一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.