pastebin - collaborative debugging tool
kpaste.net RSS

Difference between
modified post d456e5456c by Anonymous on Sun 13th Apr 2014 06:08
original post 52c60836 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);
1313
		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
}
4343
print_r($addresses);
4444
?>

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