pastebin - collaborative debugging tool
kpaste.net RSS

Difference between
modified post 27fa5185 by Anonymous on Sun 13th Apr 2014 06:35
original post d456e5456c by Anonymous on Sun 13th Apr 2014 06:08
Download diff
Show old version | new version | both versions

    
11
<?php
22
error_reporting(~E_NOTICE);
33
$handle = fopen("postcodes.txt", "r");
44
if ($handle) {
55
    while (($postcode = fgets($handle)) !== false) {
66
    	$postcode = trim($postcode);
77
    	if (empty($postcode)) continue;
88
		$ch = curl_init();
99
		$url = "http://www.dslchecker.bt.com/pls/adsl/ADSLChecker.AddressOutput?URL=&SP_NAME=a%20service%20provider&postcode=$postcode&VERSION=29&MS=E&CAP=yes&AEA=N";
1010
		curl_setopt($ch, CURLOPT_URL, $url);
1111
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
1212
		$result = curl_exec($ch);
13-
		curl_close ($ch);
13+
		curl_close($ch);
1414
1515
		$dom = new DOMDocument();
1616
		@$dom->loadHTML($result);
1717
		$finder = new DomXPath($dom);
1818
		$nodes = $finder->query("//option");
1919
2020
		foreach ($nodes as $node) {
2121
			if ($node->nodeValue == "Please select your address from the list below.") continue;
2222
    		$address = preg_split("/, /", $node->nodeValue);
2323
    		$firstline = $address[0];
2424
    		if (preg_match("/^\d+.*/", $firstline)) {
2525
    			preg_match("/^\d+/", $firstline, $number);
2626
    			$addresses[] = array(
2727
				"number" => $number[0],
2828
				"postcode" => $postcode,
2929
				);
3030
				unset($number);
3131
			} else {
3232
				if (preg_match("/^\d+.*/", $address[1])) preg_match("/^\d+/", $address[1], $number);
3333
		  		$addresses[] = array(
3434
		  		"name" => $firstline,
3535
				"number" => $number[0],
3636
				"postcode" => $postcode,
3737
				);
3838
				unset($number);
3939
			}
4040
    	}
4141
	}
4242
}
43-
print_r($addresses);
44-
?>
4543
46-
44+
foreach ($addresses as $address) {
47-
45+
	ob_start();
48-
46+
	$number = $address["number"];
49-
47+
	$name = $address["name"];
50-
48+
	$postcode = $address["postcode"];
51-
49+
	echo "$postcode\r\n";
52-
50+
	$ch = curl_init();
53-
51+
	$url = "http://www.dslchecker.bt.com/pls/adsl/ADSLChecker.AddressOutput?URL=&SP_NAME=a%20service%20provider&postcode=$postcode&buildingnumber=$number&buildingname=$name&VERSION=29&MS=E&CAP=yes&AEA=N";
54-
52+
	curl_setopt($ch, CURLOPT_URL, $url);
55-
53+
	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
56-
54+
	$result = curl_exec($ch);
57-
55+
	curl_close($ch);
58-
56+
	preg_match("/Address.*is served by Cabinet (\d+)/si", $result, $matches);
59-
57+
	$cabinet = $matches[1];
60-
58+
	echo "$name, $number, $postcode. Cabinet: ".($cabinet ? $cabinet : "EO")."\r\n";
61-
59+
	ob_flush();
62-
60+
}
63-
61+
?>

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at