pastebin - collaborative debugging tool
kpaste.net RSS

Difference between
modified post 52c60836 by Anonymous on Sun 13th Apr 2014 06:08
original post 108c by Anonymous on Sun 13th Apr 2014 05:57
Download diff
Show old version | new version | both versions

    
11
<?php
2+
error_reporting(~E_NOTICE);
23
$handle = fopen("postcodes.txt", "r");
34
if ($handle) {
45
    while (($postcode = fgets($handle)) !== false) {
56
    	$postcode = trim($postcode);
67
    	if (empty($postcode)) continue;
78
		$ch = curl_init();
89
		$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";
910
		curl_setopt($ch, CURLOPT_URL, $url);
1011
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
1112
		$result = curl_exec($ch);
1213
		curl_close ($ch);
1314
1415
		$dom = new DOMDocument();
1516
		@$dom->loadHTML($result);
1617
		$finder = new DomXPath($dom);
1718
		$nodes = $finder->query("//option");
1819
1920
		foreach ($nodes as $node) {
2021
			if ($node->nodeValue == "Please select your address from the list below.") continue;
2122
    		$address = preg_split("/, /", $node->nodeValue);
2223
    		$firstline = $address[0];
2324
    		if (preg_match("/^\d+.*/", $firstline)) {
2425
    			preg_match("/^\d+/", $firstline, $number);
25-
				echo "$number[0], $postcode\r\n";
26+
    			$addresses[] = array(
27+
				"number" => $number[0],
2630
				unset($number);
2731
			} else {
3032
				if (preg_match("/^\d+.*/", $address[1])) preg_match("/^\d+/", $address[1], $number);
31-
				echo "$firstline, $number[0], $postcode\r\n";
33+
		  		$addresses[] = array(
34+
		  		"name" => $firstline,
3238
				unset($number);
3339
			}
3440
    	}
3541
	}
3642
}
43+
print_r($addresses);
3744
?>

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