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