I ultimately want to get the text pasted into a textarea to format into an html table. The data input into the textarea would be multiple rows and columns of data.
I have been able to get the individual rows without too much trouble but I'd need to be able to get rows AND columns in order to get them into a table properly.
One issue I have is the columns are not necessarily divided by the same character. The input tends to have multiple spaces between each column (those could be trimmed down to 1 somehow perhaps).
Here is an example of the code I have that spits out the individual lines.
if (isset($_POST['Submit1'])) {
$test = isset($_POST['test'])?$_POST['test']:"";
$testlines = explode("\n", str_replace("\r", "", $test));
foreach($testlines as $lines) {
echo $lines . "</br>";
}
}
Based on a suggestion I tried using the preg_split and it now outputs a table.
if (isset($_POST['Submit1'])) {
$test = isset($_POST['test'])?$_POST['test']:"";
$testlines = explode("\n", str_replace("\r", "", $test));
echo "<table>";
foreach($testlines as $lines) {
echo "<tr>";
$cols = preg_split('/\s+|,/',$lines);
foreach($cols as $field){
echo "<td>" . $field . "</td>";
}
echo "</tr>";
}
echo "</table>";
}