Something like this should work:
<?php
if ($_POST) {
$data = trim($_POST['pastedData']);
$tabDelimitedLines = explode("\r\n", $data);
$myArray = Array();
foreach ($tabDelimitedLines as $lineIndex => $line) {
$fields = explode("\t", $line);
foreach ($fields as $fieldIndex => $field) {
if ($lineIndex == 0) {
// assuming first line is header info
$headers[] = $field;
} else {
// put the other lines into an array
// in whatever format you want
$myArray[$lineIndex - 1][$headers[$fieldIndex]] = $field;
}
}
}
$json = json_encode($myArray);
echo "Associative Array in PHP:<br>";
echo "<pre>";
var_dump($myArray);
echo "</pre>";
echo "JSON:<br>";
echo $json;
echo "<br><br>";
}
?>
<html>
<form method="post">
<label>Paste some Tab Delimited Data with Headers:</label><br>
<textarea name="pastedData"></textarea><br><br>
<button type="submit">Submit</button>
</form>
</html>