2017-01-05 31 views
1

我有一个包含有新的线路,像这样的字符串文件:把数组的内容转换为字符串与新行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 

回答

1

尝试破灭功能。

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

$result = array_unique($input); 

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

echo($newresult); 
1

使用破灭添加 “\ n” 是这样的:

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

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