-1

I've created a textarea so users can insert class codes associated to a particular module. The user will copy from excel and paste into a html textarea. for example:

enter image description here

When pasted in the textarea the above is separated by tabs. In php how would i convert each row into a seperate array? e.g. Thanks, any help would be appreciated.

array(1)
(
    [0] => "moduleA"
    [1] => "class1"
)
array(2)
(
    [0] => "moduleA"
    [1] => "class2"
)
array(3)
(
    [0] => "moduleA"
    [1] => "class3"
)
Don't Panic
  • 41,125
  • 10
  • 61
  • 80
London83
  • 21
  • 1
  • 6
  • If you are going to split on newline characters first, then I recommend the `\R` metacharacter in regex to match all newline sequences. – mickmackusa Mar 01 '22 at 22:45

1 Answers1

0

From my experiences, a new row in textarea (by default) is a \n. You can implode/explode (depends on what you want) with \n for every row. e.g explode("\n", $data);

zaidysf
  • 492
  • 2
  • 14
  • In 2022, when your advice is use `explode("\n")`, you can be sure that the question is a duplicate and can be safely closed. If you don't like the links that I have closed with, leave a comment with a better one and I'll add it to the list. – mickmackusa Mar 01 '22 at 23:07
  • i think the main of his concern is not that `explode` but the`\n`. He (maybe) doesn't know that `\n` is there or textarea translate the new row as `\n` without debug it. – zaidysf Mar 02 '22 at 03:12