将文本框输入保存为HTML格式的XML或txt文件

时间:2013-04-20 18:25:37

标签: html input textbox save

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

任何知道解决方案的人?

1 个答案:

答案 0 :(得分:0)

我推荐以下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 );
}