Are there any specific PHP functions or methods that can be used to split a string by newline characters without issues?

When splitting a string by newline characters in PHP, it's important to consider different newline representations such as "\n", "\r\n", or "\r". To handle this effectively, you can use the PHP built-in function `preg_split()` with a regular expression pattern that covers all possible newline representations. This approach ensures that the string is split correctly regardless of the newline format used.

$string = "Hello\nWorld\r\nThis is a test\rString\r";
$lines = preg_split('/\r\n|\r|\n/', $string);

foreach ($lines as $line) {
    echo $line . PHP_EOL;
}