这是我现在输出到我的data.txt
文件...
test1;test2
test3;test4
这就是我想要的
MSG 1;test1;test2;
MSG 2;test3;test4;
我的HTML
<form action="messageprocessor.php" method="POST">
Message:
<textarea name="field1"></textarea>
To:<input name="field2" type="text" />
<input type="submit" name="submit" value="Save Data">
</form>
我的PHP
<?php
if(isset($_POST['field1']) && isset($_POST['field2'])) {
$data = $_POST['field1'] . ';' . $_POST['field2'] . "\n";
$ret = file_put_contents('data.txt', $data, FILE_APPEND | LOCK_EX);
if($ret === false) {
die('There was an error writing this file');
}
else {
echo "$ret bytes written to file";
}
}
else {
die('no post data to process');
}
?>
一切都很完美,但我试图理解如何以我想要的方式输出到我的数据文件。谁能在这方面帮助我?威廉