【问题标题】:Saving text box input to XML or txt file in HTML将文本框输入保存到 HTML 中的 XML 或 txt 文件
【发布时间】:2013-04-20 18:25:36
【问题描述】:

我正在开发一个 HTML 页面项目,其中有 2 个文本框,基本上我想保存用户在文本框中输入的输入数据。我们在我的 C# 类中所做的是将所有输入保存到 XML 文件中,所以我假设有类似的方法?到 XML 或其他可以存储文本的文件?

有人知道解决方案吗?

【问题讨论】:

    标签: html input textbox save


    【解决方案1】:

    我推荐以下php脚本

       <?php
    // check that form was submitted
    //   (you'll need to change these indices to match your form field names)
    if( !empty( $_POST['firstname'] ) && !empty( $_POST['lastname'] ) ){
        // remove html tags from submission
        //   (since you don't want them)
        $firstname = strip_tags( $_POST['firstname'] );
        $lastname = strip_tags( $_POST['lastname'] );
        // create the date
        //   (you can change the format as desired)
        $date = date( 'Y-m-d' );
        // create an array that holds your info
        $record = array( $firstname,$lastname,$date );
        // save the record to your .txt file (I still recommend JSON)
        $json = json_encode( $record );
        $file = '/_server_/path/to/yourfile.txt';
        file_put_contents( $json,$file );
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-03
      • 1970-01-01
      • 1970-01-01
      • 2015-01-28
      • 2020-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多