<?php
Class CSV

{
public static function LeggiEconvalida($csvFile, $patterns, $rowLength) {

$rows = array();

if(($handle=fopen("$csvFile","r"))!==FALSE)

{
while(($row=fgetcsv($handle))!==FALSE)
{

for($i=0; $i<$rowLength; $i++){
$results[] = preg_match($patterns[$i], $row[$i]);
}

$validRow = TRUE;
foreach($results as $validField)
if(!$validField)

{
$validRow = FALSE;
break;
}

if ($validRow)
$rows[]=$row;
}
fclose($handle);
}

return $rows;
}
}