getar.php

jkiel, 12/17/2010 08:39 am

Download (702 Bytes)

 
1
<?php
2
$file = "areacodes.txt";
3
$fh = fopen($file, 'w') or die("can't open file");
4
$lcnt = 0;
5
$expr = "/class=\"txtTabla\"><div align=\"center\">(.+)<\/div><\/td>/";
6
set_time_limit(0);
7
for ($i = 0; $i <= 2900; $i = $i + 25){
8
9
        $result = file_get_contents("http://www.cnc.gov.ar/infotecnica/numeracion/indicativosinter.asp?offset=$i");
10
        preg_match_all($expr,$result,$matches);
11
        $line = '';
12
        foreach ($matches[1] as $val){
13
                $line .= '"0' . $val . '",';
14
                $lcnt ++;
15
                if($lcnt>10){
16
                        $lcnt = 0;
17
                        $line .= "\n\t\t";
18
                }
19
        }
20
        fwrite($fh, $line);
21
        echo "Completed ".($i+1)." to " . ($i + count($matches[1])) . "<br>\n";
22
        @ob_flush();
23
        @flush();
24
        
25
}
26
fclose($fh);
27
?>
28