誰かが私が正規表現で並べ替えるデータのセットを持っているのを助けてくれますか?私は正しい結果を持っていますが、私がfputcsvを呼び出そうとしているとき、スクリプトはIPであるヘッダーのないフィールドだけを印刷しています。ここ入れ子配列のPHP fputcsv。
は私のコードです:
<?php
$handle = fopen("data2.txt", "r");
if (!$handle) {
exit;
}
$customers = array();
while (($line = fgets($handle)) !== false) {
if(preg_match('/-([0-9]*)-pdt.html.*rd:(.*)\|X/i',$line,$output)){
$product = $output[1];
$customer = $output[2];
if(!isset($customers[$customer])){
$customers[$customer] = array($product);
} else {
if (!in_array($product, $customers[$customer])){
$customers[$customer][] = $product;
}
}
}
}
$file = fopen('file.csv', 'w+');
foreach ($customers as $customers[$customer])
{
fputcsv($file, $customers[$customer]);
}
var_dump ($customers);
fclose($handle);
これは私のデータは結果である:ここ
array (size=10)
'164.38.32.100' =>
array (size=2)
0 => string '21940504' (length=8)
1 => string '21940524' (length=8)
'86.11.76.246' =>
array (size=1)
0 => string '10145712' (length=8)
'185.31.96.130' =>
array (size=2)
0 => string '10139358' (length=8)
1 => string '10139458' (length=8)
'2.126.213.238' =>
array (size=1)
0 => string '10164438' (length=8)
はCSV形式です:私は置くためにどのように把握する必要があり
21940504 21940524
10145712
10139358 10139458
10164438
最初の列のIP:
164.38.32.100 21940504 21940524
ありがとうございます!今働いて – Simon
確かに、私はあなたが必要なものを整理することができたことをうれしく思いました。 – ArtisticPhoenix