使用平面文件(文本)php正确格式化我的分号数据库

This is my output to my data.txt file now...

test1;test2
test3;test4

this is what I would like it to be

MSG 1;test1;test2;
MSG 2;test3;test4;

My 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>

My PHP

<?php
if(isset($_POST['field1']) && isset($_POST['field2'])) {
    $data = $_POST['field1'] . ';' . $_POST['field2'] . "
";
    $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');
}           
?>

Everything works perfectly but I'm trying to understand how to output to my data file to the way I want it above. Can anyone help me in this area? William