With the help of Q Studio and my own research, I found that exploding with PHP_EOL worked. Here is my modified code:
function eriWpConfig(){
$wp_config = FALSE;
if ( is_readable( ABSPATH . 'wp-config.php' ) )
$wp_config = ABSPATH . 'wp-config.php';
elseif ( is_readable( dirname( ABSPATH ) . '/wp-config.php' ) )
$wp_config = dirname( ABSPATH ) . '/wp-config.php';
if ( $wp_config ) {
$string = file_get_contents( $wp_config );
$lines = explode(PHP_EOL, $string);
$modified_lines = [];
$line_count = 0;
foreach($lines as $line){
$modified_lines[] = '<span style="color: #ccc;">Line: '.sprintf("%03d", $line_count).' | </span>'.esc_html($line);
$line_count ++;
}
$code = implode('<br>', $modified_lines);
} else {
$code="wp-config.php not found";
}
echo '<pre class="code"
>Installation path: ' . ABSPATH
. "\n\n"
. $code
. '</pre>';
}