Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);
- $contents = file_get_contents("http://nl.wikipedia.org/wiki/Lijst_van_gemeenten_in_het_Vlaams_Gewest");
- $lines = explode("\n", $contents);
- $start = false;
- $file = "E:\Projects\WebApps\gemeentes.xml";
- $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<gemeentes>\n";
- $aantal = 0;
- foreach($lines as $line) {
- if(preg_match("~<a href=\"(/wiki/.+?)\"~", $line, $matches)) {
- if($matches[1] == "/wiki/Aalst_(Oost-Vlaanderen)") {
- $start = true;
- }
- if($matches[1] == "/wiki/Categorie:Alles") {
- $start = false;
- }
- if($start == true) {
- $c = file_get_contents("http://nl.wikipedia.org" . $matches[1]);
- if(preg_match("~Overige informatie~", $c)) {
- $start = strpos($c, "<a href=\"/wiki/Postcode\">Postcode</a>");
- $end = strpos($c, "<a href=\"/wiki/Netnummer\"");
- $c = substr($c, $start, $end-$start);
- preg_match_all("~(\d{4})~", $c, $results);
- $c2 = substr($c, strpos($c, "Deelgemeente</a></b><br>"));
- preg_match_all("~(<a.*>)?([a-zA-Z\-\s]+)(</a>)?(<br( /)?>|</td>)~", $c2, $results2);
- if(count($results[1]) == count($results2[2])) {
- $count = count($results[1]);
- $aantal += $count;
- for($i = 0 ; $i < $count ; $i++) {
- $xml .= "\t<gemeente>\n";
- $xml .= "\t\t<postcode>" . $results[1][$i] . "</postcode>\n";
- $xml .= "\t\t<naam>" . trim($results2[2][$i]) . "</naam>\n";
- $xml .= "\t</gemeente>\n";
- }
- }
- }
- }
- }
- }
- $xml .= "\t<totaal aantal=\"$aantal\" />\n";
- $xml .= "</gemeentes>";
- //lege lijn weghalen
- $xml = preg_replace("~^\n$~", "", $xml);
- file_put_contents($file, $xml);
- header('content-type: text/xml');
- echo $xml;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement