Numbering and empty lines

<?php
$myVar='Tom live in New York. He is an American.
Chu live in Seoul. He is a Korean.

Paul live in Paris. He is a French.
Danaki live in Tokyo. He is a Japanese.';

$myVar2 = "";

foreach (preg_split('/[[COLOR="#FF0000"]\\r[/COLOR]\
]+/', $myVar) as $i => $line) {
    $myVar2 .= ($i + 1) . $line . "<br />\
";
}

echo $myVar2;
?>

[b]result[/b]

1Tom live in New York. He is an American.
2Chu live in Seoul. He is a Korean.
3Paul live in Paris. He is a French.
4Danaki live in Tokyo. He is a Japanese.

I have the code and its result in the above.
I like to get my target result in the below.

[b]target result[/b]
1Tom live in New York. He is an American.
2Chu live in Seoul. He is a Korean.
[COLOR="#FF0000"]3[/COLOR]
4Paul live in Paris. He is a French.
5Danaki live in Tokyo. He is a Japanese.

As I remove /r in the code above, I can get the more close to my target result which is the trial result below.

[b]trail result[/b]
1Tom live in New York. He is an American.
2Chu live in Seoul. He is a Korean.
[COLOR="#FF0000"]3
4[/COLOR]
5Paul live in Paris. He is a French.
6Danaki live in Tokyo. He is a Japanese.

How can I get my target result?

The use of preg_split() is unnecessary; you can use the explode function to break the string into an array of values (by line), and then loop through these values:


<?php
$myVar='Tom live in New York. He is an American.
Chu live in Seoul. He is a Korean.

Paul live in Paris. He is a French.
Danaki live in Tokyo. He is a Japanese.';

$myVarLines = explode(PHP_EOL, $myVar);

$rowCounter = 1;

foreach($myVarLines as $line) {
	echo $rowCounter, $line, '<br />';
	++$rowCounter;
}