PHPexplode() - 如何避免空行?

Iur*_*lai 6 php explode

我认为这段代码在最后放了一个空行。如果这是真的,如何避免这种情况?

$text = explode( "\n", $text );
foreach( $text as $str ) { echo $str; }
Run Code Online (Sandbox Code Playgroud)

nat*_*per 4

在爆炸之前修剪文本。

$text = trim($text, "\n");
$text = explode( "\n", $text );
foreach($text as $str) {
    echo $str;
}
Run Code Online (Sandbox Code Playgroud)