何かのときに書いたやつ。
何だったかは思い出せない。。。
<?php class csvr { public $csv,$all = ''; public $mail,$lists = array(); public $csvname = 'tst.csv'; function __construct() { $handel = fopen($this->csvname, "r"); while(!feof($handel)){ $this->csv = fgets($handel); $this->all .= $this->csv."!!!!!"; $str = explode(',',$this->csv); $this->mail[] = $str[4]; } } function all() { $prelist = explode('!!!!!',$this->all); for($i=0;$i<count($prelist);$i++){ $ad = $this->mail[$i]; $this->makelist($ad,$prelist[$i]); } $this->mail = array_unique($this->mail); } function makelist($mat,$str) { $mnu = preg_match("/$mat/",$str,$matches); if($mnu){ $this->lists{$mat}[0] = $str; $this->lists{$mat}[1][] = $str; $this->lists{$mat}[2]++; return true; } } function writecsv() { $fp_mail = fopen('mail.csv','w'); $fp_list = fopen('list.csv','w'); $fp_now = fopen('now.csv','w'); fputcsv($fp_mail,$this->mail); foreach($this->lists as $k => $v){ fputcsv($fp_list,$this->lists[$k][1]); fputcsv($fp_now,$this->lists[$k]); } fclose($fp_mail); fclose($fp_list); fclose($fp_now); } } $c = new csvr(); $c->all(); $c->writecsv();