Hi all,

I have a problem with a textarea in a form.
The form is parsed using the split option, splitting the textarea input at each tab (\t). However, when a newline arrives in the textarea, it does not split there, but it should. Is there anyway to have PHP add a \t behind every line in the textarea before it starts splitting ?

To clarify it a bit, here's the source of the page I'm talking about:

<form method="post" action="parser.php">
<textarea cols="50" rows="10" name="test"><? echo $_POST['test']; ?></textarea>
<input type="submit" value="Go">
</form>
<?
if(isset($_POST['test'])) {
$split = split("\t",$_POST['test']);
print_r($split);
}
?>

Would be awesome 🙂

Thanks in advance,
iNF

    Basically, you want to split at every tab and newline?

    Why not just do a:

    $split = preg_split('/[\t\r\n]/', $_POST['test']);

    or more likely:

    $split = preg_split('/[\t\r\n]+/', $_POST['test']);

    With the first example you have to be wary of MS Windows newline sequences.

      Ah thanks a lot ! That works excellent 🙂 Didn't know there also was a preg_split option, but it works just fine in this case 😃

      Thanks for the quick and very useful answer 🙂

        Write a Reply...