this is very basic, if you are taking user input you should probably add some field validation but here you go:
<?php
$strOutPut = "";
if(isset($_POST['txtInput']) && trim($_POST['txtInput']) != "")
{
$arrLines = explode("\n", str_replace("\r", "", $_POST['txtInput']));
array_walk($arrLines, "trim");
foreach($arrLines as &$value)
{
$strOutPut .= str_replace(" ", "-", $value) . "\t" . $value . "\n";
}
$strOutPut = substr($strOutPut, 0, -1);
$fp = fopen('path/to/file.txt', 'w');
fwrite($fp, $strOutPut);
fclose($fp);
}
?>
<html>
<head>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<textarea name="txtInput" style="width:500px; height:300px;"><?php echo trim($strOutPut) != ""?$strOutPut:""; ?></textarea><br />
<input type="submit" name="btnSubmit" value="submit" />
</form>
</body>
</html>