0

I am getting post value from a textarea like this:

11223344
55667788
99001122
33445566
77889900

I need to form it like

Array
(
    [0] => 11223344
    [1] => 55667788
    [2] => 99001122
    [3] => 33445566
    [4] => 11223344
    [5] => 77889900
)

using explode() function in php. how it possible? I have already used explode('\n\r', $datas). thanks

Decent Dabbler
  • 22,532
  • 8
  • 74
  • 106

4 Answers4

2

Use:

preg_split("/\s+/", "11223344 55667788 99001122 33445566 77889900");
Leonardo
  • 736
  • 4
  • 11
0

You should use double quotes instead of single ones:

print_r( explode("\n", $datas) );
Glavić
  • 42,781
  • 13
  • 77
  • 107
0

Try Next :

print_r(preg_split('/\r\n|[\r\n]/', $_POST['thetextarea']));
sergio
  • 5,210
  • 7
  • 24
  • 46
0

Use Double Quotes:

Try "\n\r" (double quotes) or just "\n"

When you use '\n\r' it means search for \n\r and explode about it. It won't search for newline or carriage return. When you use double quotes, it would parse for newline or carriage return.

sanjeev mk
  • 4,276
  • 6
  • 44
  • 69