繁体   English   中英

用新行php将数组内容放入字符串中

[英]put contents of array into string with new line php

我有一个文件,其中包含新行中的字符串,如下所示:

string1
string2

我想删除重复项,所以我将它们添加到数组中,做唯一操作,以便删除重复项,现在我试图删除数组并将内容放入字符串中,以换行符(“ \\ n”)开头。

代码如下:

$input = file_get_contents('/srv/test.m3u');
$input = explode("\n", $input);

$result = array_unique($input);

foreach($result as $value){
    $newresult .= $value;
}

echo($newresult); //Comes back everything stuck together no line-breaks etc

使用implode添加“ \\ n”,如下所示:

$input = file_get_contents('/srv/test.m3u');
$input = explode("\n", $input);

$result = array_unique($input);
echo implode("\n", $result);

尝试爆破功能。

$input = file_get_contents('/srv/test.m3u');
$input = explode("\n", $input);

$result = array_unique($input);

$newresult = implode("\n",$result);

echo($newresult);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM