0

I try to explode a string into an array with:

explode('\r\n', $string);

I have a form with a text field that is used by the user to enter URLs and the URLs are separated by a new line like so:

http://www.example.com/1
http://www.example.com/2
http://www.example.com/3
http://www.example.com/4

That should split the string where a new line is found and return an array with all the new strings, but instead explode() returns an array with the original string as the frist argument.

$string = $_POST['urls'];
$arr = explode('\r\n', string);

Expected return:

$arr = ['http://www.example.com/1','http://www.example.com/2','http://www.example.com/3','http://www.example.com/4']

Actual return:

$arr = ['http://www.example.com/1
 http://www.example.com/2
 http://www.example.com/3
 http://www.example.com/4']

I know that should work as I have used it before. I must be missing something.

Rizier123
  • 58,877
  • 16
  • 101
  • 156
Radi
  • 271
  • 6
  • 19

0 Answers0