コード例 #1
0
ファイル: fox_import.php プロジェクト: krecek/nrsn
case "rc":
$osoba[jmeno]='jm';
$osoba[prijmeni]='pr';
$osoba[narozeni]='1967-11-19';
$osoba[pohlavi]='Z';
$osoba[cizinec]='N';
$osoba[rc]='6711191553';
kontrola_osoby($osoba);
echo '<pre>';
var_dump($osoba);
echo '</pre>';
echo date("H:i:s")." kontrola<br>\n";
break;

case "jmena":
$res=kontrola_jmena('Řehoř');
echo '<pre>';
var_dump($res);
echo '</pre>';
echo date("H:i:s")." kontrola<br>\n";
break;

case "csv":
$osoby=import_csv(file('gym.csv'));
echo "Nalezeno ".count($osoby)." osob<br>";
if (is_array($osoby))
   foreach ($osoby as $osoba)
      echo "$osoba[id] $osoba[jmeno] $osoba[prijmeni] $osoba[narozeni] $osoba[pohlavi] $osoba[cizinec] $osoba[email] $osoba[mobil] $osoba[error]<br>\n";
//echo "<pre>\n";
//var_dump($osoby);
//echo "</pre>\n";
コード例 #2
0
ファイル: lib.php プロジェクト: krecek/nrsn
function import_csv($radky) {
if (is_array($radky))
   foreach ($radky as $radek=>$line) {
      $items=explode(';',$line);
      if (is_array($items))
         foreach ($items as $sloupec=>$val) {
            if (ereg('^".*"$',$val)) $val=substr($val,1,-1);
            $val=trim($val);
            if (ereg('^[aAnN]$',$val)): // test 1 cizinec
               $rr[$radek][1]++;
               $tt[1][$sloupec]++;
               continue;
               endif;
            if (ereg('^[mMzZžŽ]$',$val)): // test 2 pohlavi 
               $rr[$radek][2]++;
               $tt[2][$sloupec]++;
               continue;
               endif;
            if (ereg('^[ 0123]?[0-9]\.[ 01]?[0-9]\.[12][0-9]{3}$',$val)): // test 3 datum
               $rr[$radek][3]++;
               $tt[3][$sloupec]++;
               continue;
               endif;
            if (kontrola_rc($val)): // test 4 rodne cislo
               $rr[$radek][4]++;
               $tt[4][$sloupec]++;
               continue;
               endif;
            if (ereg('^[67][0-9]{2} ?[0-9]{3} ?[0-9]{3}$',$val)): // test 5 mobil
               $rr[$radek][5]++;
               $tt[5][$sloupec]++;
               continue;
               endif;
            if (ereg('^[23459][0-9]{2} ?[0-9]{3} ?[0-9]{3}$',$val)): // test 6 telefon
               $rr[$radek][6]++;
               $tt[6][$sloupec]++;
               continue;
               endif;
            if (ereg('^[0-9]+$',$val)): // test 7 cislo
               $rr[$radek][7]++;
               $tt[7][$sloupec]++;
               continue;
               endif;
            if (ereg('@',$val)): // test 8 email
               $rr[$radek][8]++;
               $tt[8][$sloupec]++;
               continue;
               endif;
            if (kontrola_jmena($val)): // test 9 jmeno, pozor na mala/velka pismena
               $rr[$radek][9]++;
               $tt[9][$sloupec]++;
               continue;
               endif;
            if (ereg('^[^0-9_\.,()@]+$',$val)): // test 10 prijmeni
               $rr[$radek][10]++;
               $tt[10][$sloupec]++;
               continue;
               endif;
            }
     }
     
if (is_array($tt)) // vyhledani vyznamu sloupcu do $testy
   foreach ($tt as $test=>$results) {
      $max=0; $sloupec=999;
      if (is_array($results))
         foreach ($results as $key=>$val)
            if ($val>$max):
               $max=$val;
               $sloupec=$key;
               endif;
      if ($max>=3 && $sloupec<>999) $testy[$test]=$sloupec;
      }
if (!isset($testy[9])) unset($testy[10]);
if (!isset($testy[10])) unset($testy[9]);
if (abs($testy[9]-$testy[10])<>1): // jmeno a prijmeni musi byt u sebe
   unset($testy[9]);
   unset($testy[10]);
   endif;
$radek=0;
while  (isset($radky[$radek]) && count($rr[$radek])<3) $radek++; // preskoc uvodni radky
while  (isset($radky[$radek]) && count($rr[$radek])>1): // zpracuj radky s obsahem
   $items=explode(';',$radky[$radek]);
   if (is_array($items))
      foreach ($items as $sloupec=>$val) {
          if (ereg('^".*"$',$val)) $val=substr($val,1,-1);
          $items[$sloupec]=trim($val);
          }
   unset($osoba);
   if (!isset($testy[1])) $osoba[cizinec]='N';
   $osoba[cizinec]=$items[$testy[1]];
   $osoba[pohlavi]=$items[$testy[2]];
   if (ereg('^[ 0123]?[0-9]\.[ 01]?[0-9]\.[12][0-9]{3}$',$items[$testy[3]])):
      $d=explode('.',$items[$testy[3]]);
      $osoba[narozeni]=sprintf("%04d-%02d-%02d", $d[2], $d[1], $d[0]);
      endif;
   $osoba[rc]=$items[$testy[4]];
   if (ereg('^[67][0-9]{2} ?[0-9]{3} ?[0-9]{3}$',$items[$testy[5]])) $osoba[mobil]=$items[$testy[5]];
   if (ereg('^[23459][0-9]{2} ?[0-9]{3} ?[0-9]{3}$',$items[$testy[6]])) $osoba[telefon]=$items[$testy[6]];
   $osoba[id]=$items[$testy[7]]; // neni ID ale poradove cislo
   if (ereg('@',$items[$testy[8]])) $osoba[email]=$items[$testy[8]];
   if (ereg('^[^0-9_\.,()@]+$',$items[$testy[9]])) $osoba[jmeno]=$items[$testy[9]];
   if (ereg('^[^0-9_\.,()@]+$',$items[$testy[10]])) $osoba[prijmeni]=$items[$testy[10]];
   kontrola_osoby($osoba);
   $osoby[]=$osoba;
   $radek++;
   endwhile;
return $osoby;
}