将html格式保存为CSV可能吗?

I was wondering if it's possible to save the contents of a html form into csv format?

I was hoping to use it as an alternative to using a database.

PHP has some built-in functionality to help with this.

as an alternative to using a database

Keep in mind that this isn't a drop-in replacement for an actual database engine. A few things to consider:

  1. How are you going to handle multiple concurrent users? Lock the file and some users just get timeouts? Race conditions can become a bit of a problem in this setup.
  2. How are you going to query the data? If the data is expected to grow, expect also the performance to drop. You can't really optimize a CSV for queries.
  3. Are you going to have multiple tables across multiple CSV files? How are you going to keep the relational integrity of the data? The application should be responsible for the integrity of the data in motion, but the data store should be responsible for the integrity of the data at rest. A CSV has no mechanism for maintaining data integrity.

Definitely possible. Use $_POST['var'] to get the form variables, and then fwrite them to a file (with comma delimiters or however you like). Also make sure to validate your input.

Sure

Matter of fact it is very easy and could be achieved with one line (Although I would not reccomend during this in production always validate input and you would also need to append to the file)

file_put_contents("mycsvfile.csv",implode(",", $_POST))

Of course. Take your fields and just put them into a file:

$data = '"'.addslashes($first).'","'.addslashes($second).'"'."
";
file_put_contents('form.csv', $data, FILE_APPEND);

store $_POST with fputcsv

see: http://php.net/manual/en/function.fputcsv.php