2013-01-31 73 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>';