简体   繁体   English

是否可以在不使用MySQL的情况下创建HTML页面?

[英]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.

相关问题 使用选择框以html格式显示mysql数据 <li> 标记而无需使用jQuery刷新页面 - use selectbox to show mysql data in html <li> tag without refreshing page with jquery 是否可以在CSS中使用PDF作为HTML页面背景? - Is it possible to use PDF as HTML page background in CSS? 可能使用CURL创建页面的精确副本? - possible to use CURL to create exact replica of page? 是否可以将Smarty模板转换为HTML而不将其输出到页面? - Is it possible to convert Smarty template to HTML without outputting it to the page? 是否可以在没有 mysql 的情况下创建 PHP 登录系统 [暂停] - Is it possible create a PHP login System without mysql [on hold] 一个人应该在MySQL中使用/创建尽可能多的索引吗? - Should one use/create as many indices as possible in MySQL? 是否可以在HTML中创建条件? - Is it possible to create a condition in HTML? 如何使用html按钮更改页面而不丢失会话 - How to use html button to change page without losing session 是否可以创建一个实时显示数据库内容的页面,而无需在Drupal 7中重新加载页面即可进行更新? - Is it possible to create a page showing database content in real time, updating without reload page in Drupal 7? HTML页面中的数据库mysql - Database mysql in html page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM