内爆()新行不工作


implode() new line not working?

我正在尝试格式化电子邮件列表,此列表返回逗号后跟新行。我是php的新手,不太懂。

$j = json_decode($s,True);
var_dump($j);
$emails = array();
foreach ($j as $a) {
    $emails[] = $a['Email'];
}
$file = fopen( __DIR__ . DIRECTORY_SEPARATOR ."emails.txt","w");
fwrite($file, implode(','+''n' , $emails )); // <----- Right here, This doesnt wrk
fclose($file);

.是PHP中的连接操作符,而不是+。此外,新行和其他转义字符需要放在双引号中,否则它们被认为是字面量。此外,您可以通过完全消除连接并将其放入字符串中来简化此操作。

fwrite($file, implode(",'n" , $emails ));