How to exclude empty lines in pref_split
.
Asked
Active
Viewed 69 times
0
-
Can `\r` appear multiple time in the middle of the text, otherwise `trim()` the text before split it. – Feb 08 '19 at 04:07
1 Answers
0
Use the PREG_SPLIT_NO_EMPTY
flag:
$string = "Name|name
Last|f_name
";
print_r(preg_split('/\R/', $string, -1, PREG_SPLIT_NO_EMPTY));
Output:
Array (
[0] => Name|name
[1] => Last|f_name
)

Nick
- 138,499
- 22
- 57
- 95