开发者

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, Jus开发者_如何学JAVAt test lines Second test lines ) 


This should do the trick:

$string = '
Hello,

Just test lines
Second test lines
';

$data  = preg_split("#\n\s*\n#Uis", $string);
print_r($data);


throw a trim around your string, then explode it with the comma, then add the comma back on to the first element.

$arraything = explode(',', trim($string));
$arraything[0] = $arraything[0].",";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜