Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explode empty line

I am trying to explode empty line.

Here is my string variable:

$string = '
Hello,

Just test lines
Second test lines
';

I want these results:

$OUTPUT[0]='HELLO,';
$OUTPUT[1]='Just test lines
Second test lines';

My code:

$a = explode("\n\n",$string);
print_r($a);

My field results:

Array ( [0] => Hello, Just test lines Second test lines ) 
like image 719
Emad doom Avatar asked Dec 16 '22 09:12

Emad doom


1 Answers

This should do the trick:

$string = '
Hello,

Just test lines
Second test lines
';

$data  = preg_split("#\n\s*\n#Uis", $string);
print_r($data);
like image 121
Kęstutis Avatar answered Jan 02 '23 02:01

Kęstutis