function convert file echo Started file date fopen in file rb fopen ou

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?
function convert($file, &$a)
{
echo "Started $file: ".date("r")."\r\n";
$h = fopen("in/$file", 'rb');
$w = fopen("out/$file", 'wb');
while(!feof($h))
{
$s = fgets($h);
$i = strpos("CNTY",$s);
if($i===false && preg_match("/.+\<CALL\:\d+\>((R.|U[A-I])\S+)\s/", $s, $m) && isset($a[$m[1]]))
$s = $m[0].'<STATE:2>'.substr($a[$m[1]],0,2).' <CNTY:5>'.$a[$m[1]].' '.substr($s, strlen($m[0]));
fwrite($w, $s);
}
fclose($h);
fclose($w);
echo "Finished $file: ".date("r")."\r\n";
}
echo "Start: ".date("r")."\r\n";
$h = fopen('table/rda.csv','rb');
$a = array();
while(($d = fgetcsv($h, 1000, ",")) !== FALSE)
$a[$d[0]] = $d[1];
fclose($h);
if($dh = opendir('in/'))
{
while(($file = readdir($dh)) !== false)
if(substr($file,-4)=='.adi')
{
convert($file, $a);
}
closedir($dh);
}
echo "Finish: ".date("r")."\r\n";