2013-01-31 39 views
0

我想要做的是使我的输出可用于电子表格。恼人的数组标签..想要一个漂亮的输出

我希望输出中的每个项目不带数组变量或不混合在一起,但以星号开头并以%符号结尾。

<?php 

    $file = file_get_contents('aaa.txt'); //get file to string 
    $row_array = explode("\n",$file); //cut string to rows by new line 
    $row_array = array_count_values(array_filter($row_array)); 

    foreach ($row_array as $key=>$counts) { 
    if ($counts==1) 
     $no_duplicates[] = $key; 
    } 

    //do what You want 
    echo '<pre>'; 
    print_r($no_duplicates); 

    //write to file. If file don't exist. Create it 
    file_put_contents('no_duplicates.txt',$no_duplicates); 
?> 
+2

你能告诉我们你想看到输出的例子吗? –

+1

*“可用于电子表格的输出”* - 使用http://php.net/fputcsv –

+0

* item1%* item2%* item3%等等........ –

回答

1

也许这会给你想要的东西:

$str = "*" . implode("% *", $no_duplicates) . "%"; 
echo '<pre>'; 
echo $str; 
echo '</pre>';