PHP explode() - how to avoid blank lines?

explode, php

Solution

Trim the text before you explode it.

$text = trim($text, "\n");
$text = explode( "\n", $text );
foreach($text as $str) {
    echo $str;
}

Problem

I think this code puts a blank line at the end. If that is true, how to avoid this? ``` $text = explode( "\n", $text ); foreach( $text as $str ) { echo $str; } ```

Original source

Related problems