TXTファイルから新しい行で文字列を爆発することはできません

qadenza:

改行で文字列を爆発することはできませんtxtファイル

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

また、試してみました

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

任意のヘルプ?

ダイにAnantシン---アライブ:

使用ファイル()関数:

$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;

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=342754&siteId=1