What potential pitfalls should be considered when using explode() in PHP for line splitting?

When using explode() in PHP for line splitting, potential pitfalls to consider include not accounting for different line endings (such as \r\n or \n), handling empty lines, and ensuring proper error checking to prevent unexpected behavior. To address these issues, it is recommended to use the PHP_EOL constant to handle different line endings, check for empty lines before processing, and validate the input data to avoid errors.

// Example code snippet to handle line splitting with explode()

$lines = "Line 1\nLine 2\r\nLine 3\n\nLine 5";
$linesArray = explode(PHP_EOL, $lines);

foreach($linesArray as $line){
    // Skip empty lines
    if(trim($line) == ''){
        continue;
    }
    
    // Process non-empty lines
    echo $line . "\n";
}