report.php

function getinfo ($str, $farray) {
    $match = preg_grep("/$str/i", $farray);
    if (sizeof($match) > 0) {
        return trim(array_pop($match));
    }
    return false;
}

if ($handle = opendir('out/')) {
    $fp = fopen('report.csv', 'w');
    
    while (false !== ($entry = readdir($handle))) {
        if (! in_array($entry, [
                '.',
                '..'
        ])) {
            $data = array();
            $data[] = $entry;
            $farray = file('out/' . $entry);
            $farray = array_map('strtolower', $farray);
            $farray = array_map('trim', $farray);
            $farray = array_filter($farray, function ($value) {
                return $value !== '';
            });
            if ($match = getinfo("no match for", $farray)) {
                $data[] = "";
                $data[] = 'No Match';
                $data[] = "";
                $data[] = "";
            } elseif ($match = getinfo("no data found", $farray)) {
                $data[] = "";
                $data[] = "No Data";
                $data[] = "";
                $data[] = "";
            } else {
                
                if ($DomainName = getinfo("domain name:", $farray)) {
                    $data[] = trim(explode(':', $DomainName)[1]);
                    
                    if (! ($Registrar = getinfo("registrar:", $farray))) {
                        if (! ($Registrar = getinfo("registrar name:", $farray))) {
                            $Registrar = ":no Registrar";
                        }
                    }
                    
                    $data[] = trim(explode(':', $Registrar)[1]);
                    if (! ($Expiration = getinfo("expiration date:", $farray))) {
                        if (! ($Expiration = getinfo("expiry date:", $farray))) {
                            $Expiration = "";
                        }
                    }
                    
                    if (! empty($Expiration)) {
                        $Expiration = explode(':', $Expiration);
                        array_shift($Expiration);
                        $Expiration = trim(implode(':', $Expiration));
                        
                        $data[] = date('Y-m-d', strtotime($Expiration));
                    } else {
                        $data[] = '';
                    }
                } else {
                    $data[] = "";
                    $data[] = "Error: nothing found";
                    var_dump($farray);
                }
            }
            
            fputcsv($fp, $data);
        }
    }
    
    fclose($fp);
    closedir($handle);
}