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
| 1 | 1 | <?php | |
| 2 | 2 | error_reporting(~E_NOTICE); | |
| 3 | 3 | $handle = fopen("postcodes.txt", "r"); | |
| 4 | 4 | if ($handle) { | |
| 5 | 5 | while (($postcode = fgets($handle)) !== false) { | |
| 6 | 6 | $postcode = trim($postcode); | |
| 7 | 7 | if (empty($postcode)) continue; | |
| 8 | 8 | $ch = curl_init(); | |
| 9 | 9 | $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"; | |
| 10 | 10 | curl_setopt($ch, CURLOPT_URL, $url); | |
| 11 | 11 | curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); | |
| 12 | 12 | $result = curl_exec($ch); | |
| 13 | 13 | curl_close ($ch); | |
| 14 | 14 | ||
| 15 | 15 | $dom = new DOMDocument(); | |
| 16 | 16 | @$dom->loadHTML($result); | |
| 17 | 17 | $finder = new DomXPath($dom); | |
| 18 | 18 | $nodes = $finder->query("//option"); | |
| 19 | 19 | ||
| 20 | 20 | foreach ($nodes as $node) { | |
| 21 | 21 | if ($node->nodeValue == "Please select your address from the list below.") continue; | |
| 22 | 22 | $address = preg_split("/, /", $node->nodeValue); | |
| 23 | 23 | $firstline = $address[0]; | |
| 24 | 24 | if (preg_match("/^\d+.*/", $firstline)) { | |
| 25 | 25 | preg_match("/^\d+/", $firstline, $number); | |
| 26 | 26 | $addresses[] = array( | |
| 27 | 27 | "number" => $number[0], | |
| 28 | 28 | "postcode" => $postcode, | |
| 29 | 29 | ); | |
| 30 | 30 | unset($number); | |
| 31 | 31 | } else { | |
| 32 | 32 | if (preg_match("/^\d+.*/", $address[1])) preg_match("/^\d+/", $address[1], $number); | |
| 33 | 33 | $addresses[] = array( | |
| 34 | 34 | "name" => $firstline, | |
| 35 | 35 | "number" => $number[0], | |
| 36 | 36 | "postcode" => $postcode, | |
| 37 | 37 | ); | |
| 38 | 38 | unset($number); | |
| 39 | 39 | } | |
| 40 | 40 | } | |
| 41 | 41 | } | |
| 42 | 42 | } | |
| 43 | 43 | print_r($addresses); | |
| 44 | 44 | ?> |
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.
kpaste.net RSS