-1

same as title, i want converter string:

$str = "#0 C:\wamp\www\test\err\index.php(19): b('123')
#1 C:\wamp\www\test\err\index.php(27): a()
#2 {main}";

to array look like this:

$arr = array(
   0 => '#0 C:\wamp\www\test\err\index.php(19): b('123')',
   1 => '#1 C:\wamp\www\test\err\index.php(27): a()',
   2 => '#2 {main}',
);

i try using $arr = explode("\n", $str); but not working,

somebody can help me???

user3510768
  • 135
  • 2
  • 10
  • possible duplicate of http://stackoverflow.com/questions/1483497/how-to-put-string-in-array-split-by-new-line – smdvlpr Apr 12 '14 at 23:31
  • 1
    `but not working` is not how you describe what problems you ran into. – N.B. Apr 12 '14 at 23:31
  • also, your input string is using double quotes and includes many occurrences of `\t` which will be treated as tab characters. Use single quotes. – smdvlpr Apr 12 '14 at 23:33

1 Answers1

0

Try it with preg_split, which will take care of different formatted linebreaks:

$arr = preg_split('/\r\n|\r|\n/', $string);
Manuel Arwed Schmidt
  • 3,376
  • 2
  • 18
  • 28