cannot explode a string by new lines from a txt file

qadenza :

cannot explode a string by new lines from a txt file

colors.txt

rgb(15, 255, 255)
rgb(15, 255, 252)
rgb(15, 255, 249)

php

$str = file_get_contents('colors.txt');
$arr = explode(PHP_EOL, $str);
$ht = '';
foreach($arr as $el){
    $ht .= "<div class='color' style='background:" . $el . "'></div>\n";
}
echo $ht; // nothing visible on page

also tried

$arr = explode('\n', $str);
$arr = explode('\n\r', $str);
$arr = explode('\r\n', $str);
$arr = explode('LF', $str); // LF stands in notepad++

Any help?

Anant Singh---Alive to Die :

Use file() function:

$str = file('colors.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$ht = '';
foreach($str as $el){
    $ht .= "<div class='color' style='background:" . $el . "'></div>\n";
}
echo $ht;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=342144&siteId=1